Forum Moderators: open
login.php:
$time = time();
setcookie('test', 'works', $time, '/', 'www.example.com');
if(isset($_COOKIE['test']))
{$visit = $_COOKIE['test'];}
else
{echo "Nope!";}
echo $visit;
?>
logout.php:
setcookie('test', works, time()-2592000, "/", "www.example.com");
$time = time();
setcookie('test', 'works', $time, '/', 'www.example.com');
I'm dubious whether this would ever work. $time should be a unix timestamp in the future (or 0 for a session cookie) - you are setting it to the current time (as set on the server) so it is likely to expire immediately unless your server time is running fast or your local machine is running slow!?
To allow your cookie to expire in 1 hour (60*60 = 3600 seconds), try:
$time = time() + 3600;
As eelixduppy suggests, I don't believe you can reliably test whether a cookie has actually been set on the same page you are setting the cookie (in PHP) - since a cookie is ultimately set on the local machine.