[nycphp-talk] why does setcookie fail?????
Phil Powell
soazine at erols.com
Sat Sep 6 16:28:18 EDT 2003
OK this is how I did my test:
1) I go to registrering.php and register fully, thereby setting the
nordicnet_registration cookie. It's all set, everything is fine (uses
setcookie() with 0 time).
2) I close my browser
3) I reboot computer (just for safety sake)
4) I reopen my browser and go to logginn.php
5) I log in, however, setcookie() this time does NOT work, the cookie is not
set because AFTER I click the link to go to another page the
$_COOKIE['nordicnet_registration'] value is empty, thus, no cookie. HOWEVER,
header() DOES work in logginn.php!
6) I change the code in registrering.php to do header() instead of
setcookie() (remember: setcookie() works, header() does NOT work in
registrering.php)
7) I close the browser
8) I reboot computer
9) I reopen browser
10) I go to registrering.php Now THIS TIME I have header() and NOT
setcookie() instead of the reverse. I register under a new name and email..
Registration is complete, the cookie SHOULD be set. I get a link to click.
I click the link, go to my next page.. AND NO COOKIE!
So.. this is what happens:
registrering.php:
Register -> setcookie('stuff', $stuff, 0, '/') WORKS -> click link -> there
is the cookie!
Register -> header() FAILS -> click link -> NO COOKIE
logginn.php:
Login -> setcookie('stuff', $stuff, 0, '/') FAILS -> click link -> NO COOKIE
Login -> header() WORKS -> click link -> there is the cookie!
Phil
"Janwillem Borleffs" <jwb at jwbfoto.demon.nl> wrote in message
news:3f5a3e0e$0$28899$1b62eedf at news.euronet.nl...
>
> "Phil Powell" <soazine at erols.com> schreef in bericht
> news:AIq6b.126697$xf.39169 at lakeread04...
> > Ok I've had it! PHP is losing its superiority status at this point! I
am
> > beginning to HATE this language!!!!!!!!
> >
>
> PHP, nor any other language can teach the programmer the proper and
logical
> way of thinking. When you know that the third argument of a function that
> creates a cookie sets its life time, you must realize that you should pass
> it a value larger then zero to create it.
>
> > I did what you suggested and it worked.. but why is it that in
logginn.php
> > your header() solution worked, but it FAILED it registrering.php to do
the
> > EXACT SAME THING! However, THIS worked in registrering.php but FAILED in
> > logginn.php:
> >
> > setcookie('nordicnet_registration', $registrationNumber, 0, '/');
> >
>
> Then you are probably facing a conflict with cookie names which overwrite
> each other. Try other names to test this, eg:
>
> header("Set-Cookie: nordicnet_registration=1; path=/");
>
> in registering.php and
>
> header("Set-Cookie: nordicnet_registration2=1; path=/");
>
> in login.php.
>
> Also, don't forget that once a cookie has been created, it will only be
> available after a reload of the page.
>
> So:
>
> <?
> header("Set-Cookie: nordicnet_registration=1; path=/");
> echo $_COOKIE['nordictnet_registration'];
> ?>
>
> Displays nothing.
>
>
> JW
>
>
>
----- Original Message -----
From: "Brian Pang" <bpang at bpang.com>
To: "NYPHP Talk" <talk at lists.nyphp.org>
Sent: Saturday, September 06, 2003 4:23 PM
Subject: Re: [nycphp-talk] why does setcookie fail?????
> umm, with this piece of code the only instance of setcookie that I see
> is commented out
>
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
More information about the talk
mailing list