- ob_start: documentation ( source)
- time: documentation ( source)
- setcookie: documentation ( source)
- ob_end_clean: documentation ( source)
- ob_flush: documentation ( source)
<?php
ob_start();
$cookie_name = "mysiterandomuser";
$cookie_value = "justanotheruser";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");
ob_end_clean();
ob_flush();
?>
<!DOCTYPE html>
<html>
<body>
<?php
if(!isset($_COOKIE[$cookie_name])) {
echo "Cookie named '" . $cookie_name . "' is not set!";
} else {
echo "Cookie '" . $cookie_name . "' is set!<br>";
echo "Value is: " . $_COOKIE[$cookie_name];
}
?>
<p><strong>Note:</strong> You might have to reload the page to see the new value of the cookie.</p>
</body>
</html>