Using cookies in php

by Rekha 2009-10-29 15:47:15

Cookies allow the webmaster to store information about the site visitor on their computer to be accessed again the next time they visit. One common use of cookies is to store your username and password on your computer so you don't need to login again each time you visit a website.

Create a Cookie?

Syntax:

setcookie(name, value, expire, path, domain);


Example:

<?php
setcookie("user", "cookie value", time()+3600);
?>


Retrieve cookie value

Example:

echo $_COOKIE['user'];


Delete a Cookie
To delete a cookie set the expiration date to the past date.

Example:


<?php
setcookie("user", "", time()-3600);
?>

Tagged in:

1104
like
0
dislike
0
mail
flag

You must LOGIN to add comments