Cookies

Creator:
Infectionx

A cookie is a name given to a small file placed in the users temp files, this file can contain info, so that when they re-visit the site the next day, this info can be read. Well first you want to check if the user has cookies enabled in their browser. We can do that by using the sizeof() function.

if(sizeof($_COOKIE) > 0){ // Cookies Enabled } else { // Cookies Disabled }

Next you will need to know how to set cookies, we can do that by using the setcookie function.

setcookie("Cookie Name", "Cookie Value",time()+1209600);

The first part of the code is obviously what you want the cookie to be named. The second part of the code is what you want the value of the cookie to save. The third part of the code is when you want the cookie to expire, I have it set at two weeks.

if($_COOKIE['CookieName']){ echo "Cookie Here"; }

This would echo "Cookie here" if the cookies value was true.

Description:
This tutorial will teach you how to use cookies in PHP.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options