---------------------------------------------------
| Date: 2003-06-22 14:19:41 |
| Filename: cookie.php |
| Author: detour@metalshell.com |
| |
| http://www.metalshell.com/ |
---------------------------------------------------
$value)
print "$key: $value
";
/* Compare the time the cookie was set with the current time, and
if it has expired tell the client it expired a week ago so that
it can erase it. */
if(time() - $cook["expire"] >= $expire_time) {
print "Cookie set to expire.
";
setcookie("mycookie", "clearing", time()-60*60*24*7);
}
// Seconds left till the cookie expires.
print "Seconds left: " . ($expire_time - (time() - $cook["expire"])) . "
";
} else {
print "Setting cookie.";
// Build an array to store on the clients browser.
$cookieset["fish"] = "trout";
$cookieset["dog"] = "hound";
$cookieset["cat"] = "cheetah";
$cookieset["expire"] = time();
/* Serialize will turn an array into a string so that it can later be turned
back into an array by using unserialize. The serialize output is something
like:
a:4:{s:4:"fish";s:5:"trout";s:3:"dog";s:5:"hound";s:3:"cat";...}
This is very handy because it allows you to store multiple values in one,
cookie making things a little cleaner. */
/* Set the cookie to expire in one week, you would need to raise this if you
set $expire_time to greater then a week. */
setcookie("mycookie", addslashes(serialize($cookieset)), time()+60*60*24*7);
}
?>