Fluoresce Posted October 16, 2009 Share Posted October 16, 2009 Is it possible to do the following? 1) Detect if a user's cookies are disabled. 2) Ask the user to enable cookies. 3) Count the number of visitors that go through this process. Quote Link to comment https://forums.phpfreaks.com/topic/177869-solved-how-can-i-detect-if-a-users-cookies-are-disabled/ Share on other sites More sharing options...
PugJr Posted October 16, 2009 Share Posted October 16, 2009 Yes. Make a cookie. Then see if that cookie exists. If not, he has it disabled. If so, he has it enabled. You are welcome. Quote Link to comment https://forums.phpfreaks.com/topic/177869-solved-how-can-i-detect-if-a-users-cookies-are-disabled/#findComment-937847 Share on other sites More sharing options...
Fluoresce Posted October 16, 2009 Author Share Posted October 16, 2009 Yes. Make a cookie. Then see if that cookie exists. If not, he has it disabled. If so, he has it enabled. You are welcome. Great! So it can be done. I'm guessing that it has to be done with PHP. Do you know of any scripts that I can refer to? Quote Link to comment https://forums.phpfreaks.com/topic/177869-solved-how-can-i-detect-if-a-users-cookies-are-disabled/#findComment-937865 Share on other sites More sharing options...
PugJr Posted October 16, 2009 Share Posted October 16, 2009 It should be pretty simple to do. http://www.tizag.com/phpT/phpcookies.php That should give you all you need. Quote Link to comment https://forums.phpfreaks.com/topic/177869-solved-how-can-i-detect-if-a-users-cookies-are-disabled/#findComment-937887 Share on other sites More sharing options...
Adam Posted October 16, 2009 Share Posted October 16, 2009 I'm guessing that it has to be done with PHP. You don't have to use PHP, almost any web programming/scripting language should have the ability to manipulate cookies, including JavaScript. Of course if they have cookies disabled, I would have thought they'd more like the kind of user to have JS disabled as well. In addition to that tutorial you may want to take a look at the PHP manual for setcookie, for a more thorough explanation. Quote Link to comment https://forums.phpfreaks.com/topic/177869-solved-how-can-i-detect-if-a-users-cookies-are-disabled/#findComment-937906 Share on other sites More sharing options...
Daniel0 Posted October 16, 2009 Share Posted October 16, 2009 Yes. Make a cookie. Then see if that cookie exists. If not, he has it disabled. If so, he has it enabled. You are welcome. So how do you distinguish between a new user (thus without a cookie) or a person with cookies disabled? Quote Link to comment https://forums.phpfreaks.com/topic/177869-solved-how-can-i-detect-if-a-users-cookies-are-disabled/#findComment-938020 Share on other sites More sharing options...
Adam Posted October 16, 2009 Share Posted October 16, 2009 I think he's thinking of something like... setcookie('cookie_test', 1, 1); if (isset($_COOKIE['cookie_test'])) { // cookies enabled } else { // cookies disabled } Quote Link to comment https://forums.phpfreaks.com/topic/177869-solved-how-can-i-detect-if-a-users-cookies-are-disabled/#findComment-938094 Share on other sites More sharing options...
Daniel0 Posted October 16, 2009 Share Posted October 16, 2009 That will always go into the else. setcookie() doesn't populate the $_COOKIES super global. Quote Link to comment https://forums.phpfreaks.com/topic/177869-solved-how-can-i-detect-if-a-users-cookies-are-disabled/#findComment-938099 Share on other sites More sharing options...
Adam Posted October 16, 2009 Share Posted October 16, 2009 Daym! Yeah seems so. I think the only way you could do it then would be to redirect the user after setting the cookie, and check for it there.. Quote Link to comment https://forums.phpfreaks.com/topic/177869-solved-how-can-i-detect-if-a-users-cookies-are-disabled/#findComment-938103 Share on other sites More sharing options...
Fluoresce Posted October 16, 2009 Author Share Posted October 16, 2009 Excellent feedback, guys. Thank you! It seems that the only way to do it is to redirect the user to the same page after setting the cookie. Is that correct? Is it even possible? How do I go about redirecting to the same page? Quote Link to comment https://forums.phpfreaks.com/topic/177869-solved-how-can-i-detect-if-a-users-cookies-are-disabled/#findComment-938152 Share on other sites More sharing options...
gizmola Posted October 16, 2009 Share Posted October 16, 2009 That would create an infinite loop, in the case that cookies are not set, unless you also include a get param that you check. To redirect is no different than any other type of redirect -- you have the http header location method or a meta refresh. As for getting the current page, there's the really helpful $_SERVER['PHP_SELF']. Quote Link to comment https://forums.phpfreaks.com/topic/177869-solved-how-can-i-detect-if-a-users-cookies-are-disabled/#findComment-938179 Share on other sites More sharing options...
Maq Posted October 16, 2009 Share Posted October 16, 2009 Javascript has a native function for this: http://www.w3schools.com/jsref/prop_nav_cookieenabled.asp Quote Link to comment https://forums.phpfreaks.com/topic/177869-solved-how-can-i-detect-if-a-users-cookies-are-disabled/#findComment-938202 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.