Cookies_PHP_Example
Cookies_PHP_Example
Cookies are small pieces of information that websites save on your computer or phone. They help
Simple Example:
When you visit an online store and add items to your cart, cookies remember what's in the cart,
1. Remembering You: They keep you logged in so you don't need to log in every time.
2. Saving Preferences: If you choose dark mode or a specific language on a website, cookies
remember it.
3. Tracking Visits: Websites can see how often you visit and what you look at, which helps improve
their services.
Real-Life Example:
When you log into a streaming service like Netflix, cookies remember who you are, so it shows your
<?php
// Set a cookie
if (!isset($_COOKIE['username'])) {
} else {
}
// Option to delete the cookie
if (isset($_GET['delete'])) {
setcookie('username', '', time() - 3600, "/"); // Set expiration time in the past
?>
<!DOCTYPE html>
<html>
<body>
</body>
</html>