Subscribe For Free Updates!

We'll not spam mate! We promise.

Mar 9, 2013

PHP - Check if browser cookies are enabled


PHP - Check if browser cookies are enabled.


At first php reads the cookie data to see if there is already any data saved in them. If not, upon attempting to store some test data, the script refreshes the page. If no result has been returned; it is an obivous indication that cookies are disabled.


if (isset($_COOKIE['stuff'])) {
 echo "cookies enabled";
}
else {
 if(isset($_REQUEST['test_cookies'])) {
 echo "cookies disabled";
 }
 else {
 setcookie("stuff", "1", 0, "/");
 header("Location: $_SERVER['PHP_SELF']?test_cookies=1");
 }
}

TechniqZone Socializer Widget
SOCIALIZE IT →
FOLLOW US →
SHARE IT →

0 comments:

Post a Comment