This is a discussion on Strange Issues with $_Cookie within the PHP Language forums, part of the PHP Programming Forums category; Hey Guys - Ever see anything like this? I've set a cookie successfully (it is showing up correctly in my ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hey Guys - Ever see anything like this? I've set a cookie successfully
(it is showing up correctly in my cookies) but when I try to reference the cookie via $_COOKIE, it is returning an undefined, and print_r($_COOKIE) only brings up one cookie, [PHPSESSID] => 7j3r750kojkdig8k6uf34adpd7, although I've set quite a few cookies. It's happening under both mozilla and safari, yet the cookies set are appearing in both. Weird huh? Any help would be very appreciated! :) |
|
|||
|
On Aug 14, 1:00 pm, anndr0id <anndr...@gmail.com> wrote:
> Hey Guys - Ever see anything like this? I've set a cookie successfully > (it is showing up correctly in my cookies) but when I try to reference > the cookie via $_COOKIE, it is returning an undefined, and > print_r($_COOKIE) only brings up one cookie, [PHPSESSID] => > 7j3r750kojkdig8k6uf34adpd7, although I've set quite a few cookies. > It's happening under both mozilla and safari, yet the cookies set are > appearing in both. Weird huh? > > Any help would be very appreciated! :) print_r($_COOKIE) only brings up one cookie, [PHPSESSID] => > 7j3r750kojkdig8k6uf34adpd7, although I've set quite a few cookies. Looks like you have sessions running =), normal stuff can you post the code you are using to create/call the cookie, please? |
|
|||
|
On Aug 14, 1:28 pm, ELINTPimp <smsi...@gmail.com> wrote:
> On Aug 14, 1:00 pm, anndr0id <anndr...@gmail.com> wrote: > > > Hey Guys - Ever see anything like this? I've set a cookie successfully > > (it is showing up correctly in my cookies) but when I try to reference > > the cookie via $_COOKIE, it is returning an undefined, and > > print_r($_COOKIE) only brings up one cookie, [PHPSESSID] => > > 7j3r750kojkdig8k6uf34adpd7, although I've set quite a few cookies. > > It's happening under both mozilla and safari, yet the cookies set are > > appearing in both. Weird huh? > > > Any help would be very appreciated! :) > > print_r($_COOKIE) only brings up one cookie, [PHPSESSID] => > > > 7j3r750kojkdig8k6uf34adpd7, although I've set quite a few cookies. > > Looks like you have sessions running =), normal stuff > > can you post the code you are using to create/call the cookie, please? Of course. I currently have a password session on the site because it isn't public yet :) Create (setcookie.php): <?php setcookie("BW_zip", $_REQUEST['zip'], strtotime("+1 year")); setcookie("BW_address", $_REQUEST['address'], strtotime("+1 year")); setcookie("BW_phone", $_REQUEST['phone'], strtotime("+1 year")); setcookie("BW_price", $_REQUEST['price'], strtotime("+1 year")); ?> <script language="javascript"> window.location = "../index.php"; </script> Call (location.php): <?pho header("Content-type: text/xml"); if(IsSet($_COOKIE["BW_zip"])) { $locSet = "yes"; $zip = $_COOKIE["BW_zip"]; $address = $_COOKIE["BW_address"]; $phone = $_COOKIE["BW_phone"]; $price = $_COOKIE["BWW_price"]; } else { $locSet = "no"; $zip = " "; $address = " "; $phone = " "; $price = "no"; } $xmlstr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"; $xmlstr .= "<location>"; $xmlstr .= "<store locSet=\"$locSet\" zip=\"$zip\" address=\"$address \" phone=\"$phone\" price=\"$price\"></store>"; $xmlstr .= "</location>"; echo $xmlstr; ?> and in another test.php file I tried: <?php print_r($_COOKIE); ?> It all looks correct to me. Not sure why the calls aren't seeing the cookie, they are reporting all the data correctly on my computer. |
|
|||
|
> <?pho
I just noticed that. The script is correct (<?php) I just didn't select the open in copy so typed it in the email to prevent it looking like a possible error.. much like my typo. I don't think Monday ever ended for me.... :) - Ann |
|
|||
|
anndr0id wrote:
> <script language="javascript"> > window.location = "../index.php"; > </script> I think this is the key. Check out http://www.php.net/setcookie -- in particular the fourth parameter "path". Also, why use a Javascript redirect when you can use an HTTP Location header? -- Toby A Inkster BSc (Hons) ARCS [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux] [OS: Linux 2.6.12-12mdksmp, up 55 days, 5 min.] Fake Steve is Dead; Long Live Fake Bob! http://tobyinkster.co.uk/blog/2007/08/13/fake-bob/ |
|
|||
|
On Tue, 14 Aug 2007 22:27:14 +0200, Toby A Inkster
<usenet200707@tobyinkster.co.uk> wrote: > anndr0id wrote: > >> <script language="javascript"> >> window.location = "../index.php"; >> </script> > > I think this is the key. Check out http://www.php.net/setcookie -- in > particular the fourth parameter "path". Which should default to '/', i.e. every path in the domain. > Also, why use a Javascript redirect when you can use an HTTP Location > header? Good point. Either there's a domain mismatch, and the browser doesn't send this cookies to 'the other' domain or something else weird going on. First of all, check wether the same domain is used continuously. If that's the case, what does print_r(getallheaders()) (if you work with apache that is) tell you? -- Rik Wasmus |
|
|||
|
Rik wrote:
> Toby A Inkster wrote: > >> I think this is the key. Check out http://www.php.net/setcookie -- in >> particular the fourth parameter "path". > > Which should default to '/', i.e. every path in the domain. Not according to the manual, it shouldn't. -- Toby A Inkster BSc (Hons) ARCS [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux] [OS: Linux 2.6.12-12mdksmp, up 55 days, 11:40.] Fake Steve is Dead; Long Live Fake Bob! http://tobyinkster.co.uk/blog/2007/08/13/fake-bob/ |
|
|||
|
On Wed, 15 Aug 2007 10:01:21 +0200, Toby A Inkster
<usenet200707@tobyinkster.co.uk> wrote: > Rik wrote: >> Toby A Inkster wrote: >> >>> I think this is the key. Check out http://www.php.net/setcookie -- in >>> particular the fourth parameter "path". >> >> Which should default to '/', i.e. every path in the domain. > > Not according to the manual, it shouldn't. > Huh? Damn it, you're right. I always assumed it to be for some reason. Ah well, it shows I don't use cookies very often :P -- Rik Wasmus |
|
|||
|
> >>> I think this is the key. Check outhttp://www.php.net/setcookie-- in
> >>> particular the fourth parameter "path". > > >> Which should default to '/', i.e. every path in the domain. > > > Not according to the manual, it shouldn't. > > Huh? Damn it, you're right. I always assumed it to be for some reason. Ah > well, it shows I don't use cookies very often :P > Neither do I. ;) I had it in the default directory and thought it would default to that without having to put the path in... it seemed to be showing up that way in the cookie, but I threw the path and domain in and it is working successfully. Thanks :D |