<?php
$cookieName = "example";
$cookieValue = "User";
//Expires in 1 hour time
$expires = time() + 3600;
setcookie($cookieName, $cookieValue, $expires);
//To remove a cookie set the expire value to a time that has already passed
setcookie('cookieName', 'Cookievalue', time() - 1);
if (isset($_COOKIE[$cookieName])) {
echo "Hello " . $_COOKIE[$cookieName];
} else {
echo "Cookie set but page needs to be reloaded.";
}
?>
A cookie will not be registered until you have refreshed the page or moved on to a different page, this also applies to removing cookies.
Be the first to 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.