Cookies having to be set twice

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
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Cookies having to be set twice

Post by GeXus »

I've been having some issues with cookies... Here's the code i'm using to test

Code: Select all

 
<?
$guid = rand(0,500);
setcookie('guid', $guid, time()+(60*60*24*365));
print_r($_COOKIE);
echo $_COOKIE['guid'];
?>
 
The way I would expect this to work is to set the cookie and print the cookie... but instead, it only displays the cookie info if I refresh the page, any ideas? and no I don't want to use sessions.
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Re: Cookies having to be set twice

Post by GeXus »

Another thing that is weired, is even if the cookie is showing as set (after refresh), if I try to print that cookie from another page, it doesn't print.
Post Reply