Cookie is a small file that identifies the users on the user's computer.
whenever the same computer request to the server for the same page, the browser will send the cookie with the request.
To create Cookie we can use the setcookie() function.
Syntax
setcookie(name, value, expire, path, domain, secure, httponly);
To modify a cookie use the same function setcookie() with different argument values. If we required to delete the cookie after a certain time we can set expiration time in that function.
for example :
<!DOCTYPE html>
<?php
$cookie_name = "user";
$cookie_value = "Arjun";
setcookie($cookie_name, $cookie_value, time() + (36400 * 30), "/");
?>
<html>
<body>
<?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];
}
?>
</body>
</html>
0 Comment(s)