PHP –– Cookies
written by: admin
Date Written: 10/29/08
Last Updated: 10/9/22
<?php
$value="hi";
setcookie("Test", $value, time()+3600);
echo $_COOKIE["Test"];
?>
The above will create a cookie called
Test that will expire in one hour. The value can be set to the variable $cookie with the following
$cookie = $_COOKIE["Test"];
A cookie is stored on user's browser to remember small facts. It is handy for keeping a person logged in so as to avoid logging in everytime a browser is opened.
Cookies are often greatly limited in number per site and user and size whereas sessions are not. Sessions can be given expiration dates by changing the behavior in the php.ini file.
See: Difference between Session and Cookies
TAGS: php