I’m writing a little in-house script and thought I’d use cookies instead of sessions.
I can’t get the $_COOKIE[‘last’] index to stay after refresh:
<?php
setcookie("user", "Joe", time() + 3600*24);
?>
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<?php
$_COOKIE['last'] = "Y";
var_dump($_COOKIE);
?>
</body>
</html>
On a different script, I simply tried to echo $_COOKIE[‘last’] , but got a notice that it’s not there. var_dump() proves that:
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<?php
var_dump($_COOKIE);
echo $_COOKIE['last'];
?>
</body>
</html>
It’s been a while since I worked with cookies. What am I missing?
In the meantime, I’m back to successfully using sessions.