Strange Issues with $_Cookie

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


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-14-2007
anndr0id
 
Posts: n/a
Default Strange Issues with $_Cookie

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

Reply With Quote
  #2 (permalink)  
Old 08-14-2007
ELINTPimp
 
Posts: n/a
Default Re: Strange Issues with $_Cookie

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?

Reply With Quote
  #3 (permalink)  
Old 08-14-2007
anndr0id
 
Posts: n/a
Default Re: Strange Issues with $_Cookie

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.

Reply With Quote
  #4 (permalink)  
Old 08-14-2007
anndr0id
 
Posts: n/a
Default Re: Strange Issues with $_Cookie

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


Reply With Quote
  #5 (permalink)  
Old 08-14-2007
Toby A Inkster
 
Posts: n/a
Default Re: Strange Issues with $_Cookie

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/
Reply With Quote
  #6 (permalink)  
Old 08-14-2007
Rik
 
Posts: n/a
Default Re: Strange Issues with $_Cookie

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
Reply With Quote
  #7 (permalink)  
Old 08-15-2007
Toby A Inkster
 
Posts: n/a
Default Re: Strange Issues with $_Cookie

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/
Reply With Quote
  #8 (permalink)  
Old 08-15-2007
Rik
 
Posts: n/a
Default Re: Strange Issues with $_Cookie

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
Reply With Quote
  #9 (permalink)  
Old 08-15-2007
anndr0id
 
Posts: n/a
Default Re: Strange Issues with $_Cookie

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



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:45 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0