Web EndMemo

PHP Cookie


setcookie() function defines a cookie. Cookie must be sent before any output of the web page.

setcookie($name, $value, $expire, $path, $domain, $secure, $httponly)
$name: cookie name, optional
$value: cookie value, optional
$expire: time for the cookie to expire, in seconds, optional
$path: path the cookie will work. if "/", it works on the whole domain, optional
$domain: domain the cookie will work. "endmemo.com" works for all like "www.endmemo.com" and "tutorial.endmemo.com", optional
$secure: worked only over a secure HTTPS protocol, default is FALSE, optional
$httponly: work only over a HTTP protocol, default is FALSE, optional

<?PHP
setcookie("login","mike"); //set cookie "login" with value "mike"
setcookie("login","mike", time()+3600); //expire after 1 hour
setcookie("login","mike", time()+3600,"/program/","endmemo.com"); 
//expire after 1 hour
echo "$_COOKIE["login"]";  //show cookie value
?>

To delete cookie, set its expiration time to the past:
<?PHP
setcookie("login","mike", time()-60); //expired 1 minute ago
?>