cookie not getting set

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cneeds
Forum Newbie
Posts: 24
Joined: Tue Sep 14, 2010 1:39 am

cookie not getting set

Post by cneeds »

Hi

I'm setting a cookie at the top of fileA.php:

Code: Select all

<?php
setcookie('client_internal_ID', $_GET['client_internal_ID'], 0, "/");
fileA.php calls fileB.php with:

Code: Select all

<form name="AADform" method="post" id="userform" action="fileB.php">
When I retrieve 'client_internal_ID' from $_COOKIE it has a value that it was set to a few days ago. Does anybody have an idea of what I've broken?

Here is the code in fileB.php:

Code: Select all

echo("client_internal_ID=".$_COOKIE['client_internal_ID']);
Chris
Last edited by cneeds on Sat Oct 02, 2010 9:39 am, edited 3 times in total.
cneeds
Forum Newbie
Posts: 24
Joined: Tue Sep 14, 2010 1:39 am

Re: cookie not getting set

Post by cneeds »

Maybe it's a name thing? Can $_GET['client_internal_ID'] and $_COOKIE['client_internal_ID'] exist at the same time?

Chris
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: cookie not getting set

Post by DigitalMind »

cneeds wrote:Can $_GET['client_internal_ID'] and $_COOKIE['client_internal_ID'] exist at the same time?
Yes
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: cookie not getting set

Post by califdon »

In your post there are html entities, like & # 4 0 ; (I had to space them out so they wouldn't be changed to just "(" ) -- are these artifacts of your copying and pasting?? If they are in your code, I imagine that's your problem. That's unacceptable as PHP code. Your code should look like this:

Code: Select all

setcookie('client_internal_ID', $_GET['client_internal_ID'], 0, "/");
cneeds
Forum Newbie
Posts: 24
Joined: Tue Sep 14, 2010 1:39 am

Re: cookie not getting set

Post by cneeds »

sorry about the copy n paste heiroglyphics, I didn't notice until you pointed it out... Oops, how do I stop that from happening? Pass it through notepad or something?
___

I'm really stuck on this one. ran out out ideas completely...
cneeds
Forum Newbie
Posts: 24
Joined: Tue Sep 14, 2010 1:39 am

Re: cookie not getting set

Post by cneeds »

califdon wrote:In your post there are html entities, like & # 4 0 ; (I had to space them out so they wouldn't be changed to just "(" ) -- are these artifacts of your copying and pasting?? If they are in your code, I imagine that's your problem. That's unacceptable as PHP code. Your code should look like this:

Code: Select all

setcookie('client_internal_ID', $_GET['client_internal_ID'], 0, "/");
Sorry, I had the wrong tags...

Chris
cneeds
Forum Newbie
Posts: 24
Joined: Tue Sep 14, 2010 1:39 am

Re: cookie not getting set

Post by cneeds »

I found the problem.

I was unsetting the cookie with the unset command but that wasn't destroying the cookie so I had to setcookie("client_internal_ID","",time() - 60*60);
to really clear it!

Chris
Post Reply