JoshWegener
asked on
Set Cookie not working
I created a test page at http://www.cmga.us/test2.php with this code...
-----------------
<?PHP
print_r($_COOKIE);
if ( !setcookie("asrf", "asdf", 0) )
echo '-failed!';
?>
-----------------
It all ways fails... why?
-----------------
<?PHP
print_r($_COOKIE);
if ( !setcookie("asrf", "asdf", 0) )
echo '-failed!';
?>
-----------------
It all ways fails... why?
The third variable in a cookie is a time variable. In your example, you are setting a cookie for exactly 0 seconds, which isn't very much of course. Try using the value 3600 there (= 1 hour) and see how it goes then.
^ exactly.
bool setcookie ( string $name [, string $value [, int $expire [, string $path [, string $domain [, bool $secure [, bool $httponly]]]]]] )
http://php.net/setcookie
bool setcookie ( string $name [, string $value [, int $expire [, string $path [, string $domain [, bool $secure [, bool $httponly]]]]]] )
http://php.net/setcookie
ASKER
Well, I changed that, but it still fails
Move:
print_r($_COOKIE);
to AFTER trying to set a cookie.
print_r($_COOKIE);
to AFTER trying to set a cookie.
ASKER
it prints out FAILED when it does not work... there is no need to move that. You can also just hit refresh.... because if it did store it in a cookie, it would display the value.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.