setcookie()
` function to set the cookie, and `$_COOKIE
` superglobal array to retrieve its value. Here's an example :<?php
// Set a cookie with name "user" and value "John Doe" that expires in 1 day
setcookie("user", "John Doe", time() + (86400 * 1), "/");
// Retrieve the value of the "user" cookie
if(isset($_COOKIE["user"])) {
echo "Welcome " . $_COOKIE["user"] . "!";
} else {
echo "Cookie is not set!";
}
?>
$_COOKIE
` superglobal array and check if it is set using the `isset()
` function.