A cookie is a small piece of data that the web server sends to a web browser so that the web server can keep track of user‟* activity on a particular website.
When a user uses a computer to visit a website, the website stores some basic information about the visit on the hard disk of the computer. It records the user‟* preferences while using the site. This stored information is called a "cookie".
<?php
$cookie_name = "car";
$cookie_value = "BMW";
setcookie($cookie_name, $cookie_value, time() + (86400 * 2), "/"); // 86400 = 1 day ?>
<?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];
}
?>