Re: Cookies detect and $_SESSION
| From: | 1LT John W. Holmes | Date: | Tue, 06 Aug 2002 00:36:20 +0000 |
| Subject: | Re: Cookies detect and $_SESSION | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-111306@lists.php.net to get a copy of this message | ||
> Hi John,
>
> That makes sense. I guess it's brain-bloat. I've never bothered using
> $_COOKIE simply because I thought I wasn't using them. So I'll give that a
> try.
>
> But getting back to my earlier question, when I switch off cookies in
Opera
> or Konqueror browser, and print_r($_SESSION); the result is Array(). Now,
> that's telling me that the 'yes' was not passed to the $_SESSION. How come
I
> cannot set a condition of 'null' or "" to determine/use this condition?
I've
> tried switch, and if. They don't detectt it. Why? I've added some comments
> below as well.
It's kind of hard to follow that without seeing your actual code. Are you
doing print_r on the second page?
---John Holmes...
> Regards, Andre
>
> On Monday 05 August 2002 07:38 pm, 1LT John W. Holmes wrote:
>
> > You don't say _how_ it "doesn't work" but I assume it always tells you
the
> > "cookie" was set.
>
> Correct.
> >
> > You're not setting any cookie values at all. Look at what you're
actually
> > doing:
> >
> > $_SESSION['cookie'] = "yes";
> > if($_SESSION['cookie'] == "yes")
> >
> > Umm..that's _always_ going to be true.
>
> Not always. If $_SESSION['cookie'] does not get 'passed' to $_SESSION
(which
> it doesn't when I view it wih print_r($_SESSION);).
>
>
> >
> > If you want to set a cookie value, you got to have a page refresh.
Cookies
> > are not set until the next page is requested... So, you could have
> > something like this:
> >
> > //set cookie
> > $_COOKIE['test'] = "test";
> > //redirect to new page
> > header("Location:
> > http://www.example.com/index2.php");
> >
> > Then, on index2.php
> >
> > //see if cookie is not set
> > if(!isset($_COOKIE['test']))
> > { echo "Cookies must be enabled!"; }
> >
> > Hope that helps...
> >
> > ---John Holmes...
> >