if (isset($_COOKIE['username'])) { echo "Welcome back, " . $_COOKIE['username'] . "!"; } else { echo "Please log in."; }
function checkCookie($cookieName) { if (isset($_COOKIE[$cookieName])) { return true; } else { return false; } } if (checkCookie('visited')) { echo "You have already visited this website."; } else { setcookie('visited', 1, time()+3600); // set the cookie to expire in 1 hour echo "Welcome to our website!"; }This example defines a function that checks if a specified cookie exists. It is then used to check if the "visited" cookie exists. If it does, it displays a message letting the user know they have already visited the website. If it doesn't, it sets the cookie and displays a welcome message. Package library: PHP built-in function