Jump to content

[SOLVED] Problem: Cookies enabled or not?


Recommended Posts

I'm trying to write a basic function to check whether or not the user has cookies enabled (So I can decide if I want mod_rewrite turned on or not, among other things)*, but I'm having some problems.

 

public function CookiesAllowed() {
	//If cookie allowed exists, return 1... If not, try to set it for 2 weeks - if fails, return 0... If successful return 1
	return (isset($_COOKIE['allowed'])) ? 1 : setcookie("allowed", "true", time()+60*60*24*30);
}

 

I'm using IE7.0 to test, I set it to ask me every time a cookie is set, and have the cookies array output using print_r... Even if I deny the cookie, and it doesn't show in the array (After several refreshes), this function still returns 1.

Setcookie should return 0 if the cookie wasn't set properly, but it always returns 1 for some reason - any ideas why? Any way I can fix this?

 

 

*I'd rather not have to edit all of my mod_rewrite rules to have SESSID on the end, so I just let PHP handle it and turn mod_rewrite off if the user isn't allowing cookies.

Link to comment
https://forums.phpfreaks.com/topic/103686-solved-problem-cookies-enabled-or-not/
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.