Why we create cookies ?
cookie is used to identify any user. A cookie is known as a very small file that the server copy into the user's computer browser. Whenever users request a web page using the same computer , it will send the cookie too.
With PHP, We can create and retrieve cookie values.
For creating cookie. setcookie() function is called.
<?php
$cookie_name = "Username";
$cookie_value = "David Marker";
setcookie($cookie_Username, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day // used to create the cookies
?>
For retreiving any cookie we can write the code=
<?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];
}
?>
0 Comment(s)