How to set cookie expire time using php?
Snippet Code
This php code can be used to set expire time. Using time() 1*60, you can change the desired expiration time.
<?php
$cookie_name = "admin";
$cookie_value = "hscripts";
setcookie($cookie_name, $cookie_value, time()+1*60, "/"); //1*60 seconds(1minute)
if(!isset($_COOKIE[$cookie_name])) {
echo "Cookie named '" . $cookie_name . "' is not set!";
} else {
echo "Cookie '" . $cookie_name . "' is set!
";
echo "Value is: " . $_COOKIE[$cookie_name];
}
?>
Tags