note 35911 deleted from function.setcookie by didou
| From: | didou@php.net | Date: | Fri, 19 Sep 2003 07:20:39 +0000 |
| Subject: | note 35911 deleted from function.setcookie by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-56746@lists.php.net to get a copy of this message | ||
Note Submitter: brett@brettbrewer.com
----
How to check to see if browser cookies are enabled:
Apparently similar functionality is available in phpsniff on sourceforge, but the author didn't
bother documenting that project, so I had no way of knowing how it worked. I decided to write a
routine using sessions.
We use sessions here for simplicity. Basically, we just want to set a cookie, then reload the page
to see if it was set and if so, set a variable flag and delete the cookie.
<?php
session_start();
if( !$_SESSION['cookietest']['reload'] ||
$_SESSION['cookietest']['reload']=="yes" ){
setcookie("cookietest",'yes',0,'/','',0);
$_SESSION['cookietest']['reload']="no";
header("Location: $_SERVER[PHP_SELF]");
exit;
}else{
$cookies_on=$_COOKIE['cookietest'];
setcookie("cookietest",'',time()-3600,'/','',0);
$_SESSION['cookietest']['reload']="yes";
}
echo "Cookies On: $cookies_on";
?>