Need PHP to see cookie on first reload, not second.
Moderator: General Moderators
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
Need PHP to see cookie on first reload, not second.
PHP seems to have a problem with not seeing a cookie on a reload and will not see it until the page reloads twice! This creates a timing issue in a sense, what is possibly causing this and how do I fix it?
John
John
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
PHP reads cookie on first reload...
Thanks Jenk, that was exactly the problem!
Here is an example for others to test it out with...
Here is an example for others to test it out with...
John<?php
echo $_COOKIE[example];
?>
<br />
<a href="#" onmousedown="document.cookie='example=1;path=/;time()+314496000;'" onmouseup="window.location.href=window.location.href">1</a> - <a href="#" onmousedown="document.cookie='example=2;path=/;time()+314496000;'" onmouseup="window.location.href=window.location.href">2</a>
also, you should be using the $_COOKIE array like so: note the quotes, if the key is a string it must be treated as a string. 
Code: Select all
echo $_COOKIE['example'];- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
you put
instead of
when a value appears that is not a string (specified by surrounding it with single quotes) php will look for a constant with that name, if it can't find it it assumes a string [and throws an E_NOTICE error if I'm not mistaken], you probably wouldn't notice any ramifications in the way you're using it but you could sometimes have a constant with the same name as an array key in a larger application
Code: Select all
echo $_COOKIE[example];Code: Select all
echo $_COOKIE['example'];when a value appears that is not a string (specified by surrounding it with single quotes) php will look for a constant with that name, if it can't find it it assumes a string [and throws an E_NOTICE error if I'm not mistaken], you probably wouldn't notice any ramifications in the way you're using it but you could sometimes have a constant with the same name as an array key in a larger application
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact: