I put an example script up on my site:
http://www.justanotherwebsite.com/cookies.php
here's the code:
cookie_test.php
<?php
$cookie_expire = time()+60*60*12;//expire in 12 hours
$cookie_domain = 'mydomain.com';//change to your domain or IP address
$cookies = 0;//if cookies are accepted, set to 1
/*
for some versions of internet explorer, you need to specify all attributes in
setcookie. It may be necessary to set path and domain
,'/',$cookie_domain
*/
//cookie_test.php
if(isset($_COOKIE['mycookie'])){
//everything's good, update the cookie
setcookie('mycookie',$_COOKIE['mycookie'] + 1,$cookie_expire);//,'/',$cookie_domain
$cookies = 1;
} else if(isset($_COOKIE['test_cookie'])){
//they can accept cookies, set mycookie
setcookie('mycookie',1,$cookie_expire);//,'/',$cookie_domain
$cookies = 1;
} else if(!isset($_COOKIE['test_cookie']) && $_GET['cookies'] == 1){
/*
this is the cookie test, if $_GET['cookies'] is set and $_COOKIE['test_cookie']
is not, then they don't have cookies enabled.
do your non-cookie code here.
*/
} else {
/*
mycookie wasn't set, neither was test_cookie or cookies
set test cookie, then the script refreshes itself with cookies=1
*/
setcookie('test_cookie',1,$cookie_expire);//,'/',$cookie_domain
header("Location: " . $PHP_SELF . "?cookies=1");
}//end if-else
?>
cookies.php
<?php include("cookie_test.php"); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>See if cookies exist</title>
</head>
<body>
<?php
if($cookies){
print "cookies are enabled";
} else {
print "cookies are NOT enabled";
}//end if
?>
</body>
</html>