PHP cookies
PHP cookies - Dec 13, 2008 at 22:00 PM by Rajmeet Ghai
A cookie is used for identification purposes. It is more commonly used to
identify a user in a session. It is a small file the application inserts on the
users computer. With PHP one can create and retrieve the cookie.
Setting cookie in php:
Cookies in PHP can be set using the setcookie() function. This must appear
before the HTML tag.
Syntax:
Setcookie(name, value, expire, path, domain);
Example: here, the cookie name sample is assigned a value jim.
The cookie expires after an hour.
Setcookie(“sample”, “jim”, time()+3600);
Retrieving cookie value:
The cookie that is set can be retrieved as shown below:
Echo $_cookie[“user”];
Isset() function can be used to find if the cookie is set.
|