How do I get the cookies to persist in php?
give_cookie.php
<?php
if (!isset($_COOKIE["muffin"]))
setcookie("muffin", "55", 100 * 60 * 60 * 24 * 30);
$_COOKIE["lid"]=true;
?>
jar.php
<?php
var_dump($_COOKIE);
if($_COOKIE["lid"])
echo "open";
?>
Running the code in that order gives me output:
array(0) { } Notice: Undefined index: lid in jar.php on line 3
Embedding the code from jar.php
in give_cookie.php
gives me output:
array(1) { ["lid"]=> bool(true) } open
You're supposed to give a UNIX timestamp of when the cookie will expired (calculated since the epoch) as the third argument to the function call.
I suggest you read the documentation for
setcookie
.