Jump to content

Checking If Cookies Are Allowed


floridaflatlander

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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.