How To Set A Cookie

What’s a cookie you ask?

Cookies are little pieces of text that are sent to a user’s Web browser. Cookies can help you create shopping carts, user communities, and personalized sites. It’s not recommended that you store sensitive data in a cookie, but you can store a unique id string that will match a user with the data held securely in a database.

Enough with the boring stuff here is how to set a cookie using the setcookie() command.

This following line is an example of a cookie called id with a value of 55sds809892jjsj2. This particular cookie will expire in four hours(the current time plus 14,400 seconds), adn it is valid for any page below the document root on the domain

setcookie("id", "55sds809892jjsj2", time()+14400, "/", "", 0);

Time sheet, the following is a short list of how long you can set a cookie.

time()+60      One minute from the current time
time()+900     15 minutes ""
time()+1800    30 ""
time()+3600    One hour ""
time()+14400   Four hours ""
time()+43200   12 ""
time()+86400   24 ""
time()+259200  Three days ""
time()+604800  One Week ""
time()+2592000 30 days ""

That’s all for now

I hope it has been a useful article