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.
Comments
Post new comment