Jump to content

Checking If Cookies Are Allowed


Recommended Posts

I would have thought this would have been beat to death on here by now but I searched for "Check for cookies" and I didn't see this topic.


On a site I'm making, users can't login without cookies inabled.


// I have an included fucntion file and I have this near the top
if (!isset($_COOKIE['AllowCookies']) OR $_COOKIE['AllowCookies'] != 'Yes') {setcookie("AllowCookies", Yes);} // To check to see if browser accepts cookies

// then on the login page I have

if ($_COOKIE['AllowCookies'] != 'Yes') {echo '<p style="color: red;">Sorry, your cookies are turned off. You must allow them in your browser to login. Thank you</p>';}


I searched the web and came up with more verbose examples which makes me wonder if this is good enough or if I'm missing something.

So my question is, will this do?

Edited by floridaflatlander
Link to comment
Share on other sites

The best way to check for cookies is using javascript. There should be plenty of JS cookie checkers out there, where you basically set a cookie in Javascript, check for it in PHP, if that cookie is not there, they either have JS Disabled and or Cookies disabled.


I have never really seen it done properly in PHP, because you have to do a page reload to attempt to read the cookie, where as JS there is no reload done.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.