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.
The time the cookie expires. This is a Unix timestamp so is in number of seconds since the epoch. In other words, you'll most likely set this with the time() function plus the number of seconds before you want it to expire. Or you might use mktime(). time()+60*60*24*30 will set the cookie to expire in 30 days. If set to 0, or omitted, the cookie will expire at the end of the session (when the browser closes).
I suggest you read the documentation for setcookie
.