Reputation: 89
I have this code
<?php
setcookie('page', 'settings', time(),'/');
header('Location: settings.php');
?>
but every time I check the cookie with $_COOKIE['page'] is empty?
Upvotes: 2
Views: 49
Reputation: 13558
The cookie you are sending expires at the moment you send it.
setcookie("TestCookie", $value, time()+3600); /* expire in 1 hour */
Upvotes: 1
Reputation: 39704
Your cookie always expires, use:
setcookie('page', 'settings', time()+3600,'/'); // + 1 hour
also add a an exit for your script in case you have something bellow header:
<?php
setcookie('page', 'settings', time()+3600, '/');
header('Location: settings.php');
exit();
?>
Upvotes: 5