Wednesday, April 7, 2010

Cookies

A cookie is a small file that the server embeds on the user's computer and usually used to identify a user.



Create a Cookie

Syntax:



For instance, we create a cookie named "valid_user" and assign a value "Abdul Razzaq" to it. We also specify that the cookie should expire after 30 minutes:


(click image to view)



Retrieve a Cookie Value

You will use $_COOKIE variable to retrieve a cookie value. For instance:


(click image to view)

In the following example we will use isset() function to find out if a cookie has been set:


(click image to view)



Delete a Cookie


(click image to view)



Browser Does Not Support Cookies?

There is one method to solve this problem. All you need to do is to pass the data through forms (previously described in this tutorial. Click here)

No comments:

Post a Comment