Cookie Class

class Cookie { public static function exists($name) { return (isset($_COOKIE[$name])) ? true : false; } public static function get($name) { return $_COOKIE[$name]; } public static function put($name, $value, $expiry) { if(setcookie($name, $value, time() + $expiry, '/')) { return true; } return false; } public static function delete($name) { self::put($name, '', time() - 1); } }
This class added a cookie to the users browser to remember them.

3 Responses

Example:
if (!Cookie::exists("User")){
if (Cookie::put("User","Leo",time()+31536000)){
echo "User name: ".Cookie::get("User");
}
}

:)
public static function delete($name) {
self::put($name, '', 1);
}

Much cleaner way of expiring and doesn't require the use of a function, the time() timezone from the user or code, the mess involved with it, and simple does what you need.
even better would be:

public static function delete($name = '') {
$return = FALSE;
$name = trim($name);
if(!empty($name)
{
self::put($name, '', 1);
$return = TRUE;
}

return $return;
}

Write a comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.