To set your cookies:
// Set your cookies (you need to set the path as well as the domain
setcookie("user", $namecookie, time() + 86400, "/", "theutherfish.com");
setcookie("time", time(), time() + 86400, "/", "theutherfish.com");
Then to check them, use this:
// This is quite an insecure way of going about it though, it's piss easy to spoof a cookie
if(isset($_COOKIE['user'])) {
echo "Welcome, ".$_COOKIE['user']."!";
} else {
echo "Welcome Guest!";
}
Then to unset your cookies you need to set the expiry time to a previous date. I use now, minus 1 day, to account for timezones 🙂
// Unset the cookies
setcookie("user", "", time() - 86400, "/", "theutherfish.com");
setcookie("time", "", time() - 86400, "/", "theutherfish.com");
// And just to make sure (this shouldn't make a difference, but it has before, so it's included)
unset($_COOKIE['user']);
unset($_COOKIE['time']);
Hope that helps,
Matt