Strange Issues with $_Cookie

Strange Issues with $_Cookie

am 14.08.2007 19:00:33 von anndr0id

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! :)

Re: Strange Issues with $_Cookie

am 14.08.2007 19:28:28 von ELINTPimp

On Aug 14, 1:00 pm, anndr0id 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?

Re: Strange Issues with $_Cookie

am 14.08.2007 21:58:18 von anndr0id

On Aug 14, 1:28 pm, ELINTPimp wrote:
> On Aug 14, 1:00 pm, anndr0id 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):
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"));
?>



Call (location.php):
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 = "\n\n";
$xmlstr .= "";
$xmlstr .= " \" phone=\"$phone\" price=\"$price\">";
$xmlstr .= "
";

echo $xmlstr;
?>

and in another test.php file I tried:

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.

Re: Strange Issues with $_Cookie

am 14.08.2007 22:00:39 von anndr0id

>
I just noticed that. The script is correct ( 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

Re: Strange Issues with $_Cookie

am 14.08.2007 22:27:14 von Toby A Inkster

anndr0id wrote:

>

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/

Re: Strange Issues with $_Cookie

am 14.08.2007 23:46:28 von luiheidsgoeroe

On Tue, 14 Aug 2007 22:27:14 +0200, Toby A Inkster =

wrote:

> anndr0id 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.

> 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 i=
s) =

tell you?
-- =

Rik Wasmus

Re: Strange Issues with $_Cookie

am 15.08.2007 10:01:21 von Toby A Inkster

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/

Re: Strange Issues with $_Cookie

am 15.08.2007 10:46:25 von luiheidsgoeroe

On Wed, 15 Aug 2007 10:01:21 +0200, Toby A Inkster
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

Re: Strange Issues with $_Cookie

am 15.08.2007 16:18:28 von anndr0id

> >>> 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