\n"; echo "

Source Code:

\n"; highlight_file($_SERVER['DOCUMENT_ROOT'] . $_SERVER['PHP_SELF']); echo "\n"; exit; } if(!isset($_GET['mode'])) { // Clear all cookies. Do this at start, and again when we're finished. clearcookies(); unlink($clogfile); if (!isset($_GET['test'])) { header("Location: $ctestfile?mode=1"); } exit; } if($_GET['mode'] == 1) { // Try setting all the cookies $time = mktime()+600; $date = gmstrftime("%A, %d-%b-%Y %H:%M:%S", (mktime()+6400)); header("Set-Cookie: testcookie1=present;"); header("Set-Cookie: testcookie2=present; expires=$date"); header("Set-Cookie: testcookie3=present; expires=$date; path=/"); header("Set-Cookie: testcookie13=present; path=/; domain=$HTTP_HOST; expires=".gmstrftime("%A, %d-%b-%Y %H:%M:%S GMT",time()+9600)); setcookie("testcookie4", "present"); setcookie('testcookie5', 'present', (time()+6400)); setcookie('testcookie7', 'present', (time()+6400), '/', $HTTP_HOST); print "\n"; print "\n"; print "\n"; print "\n"; sleep(5); if (!isset($_GET['test'])) { print "\n"; } exit; } if($_GET['mode'] == 2) { // Check and log results if($_COOKIE ['testcookie1'] != 'present') if($_COOKIE ['testcookie2'] != 'present') if($_COOKIE ['testcookie3'] != 'present') if($_COOKIE ['testcookie4'] != 'present') if($_COOKIE ['testcookie5'] != 'present') if($_COOKIE ['testcookie7'] != 'present') if($_COOKIE ['testcookie9'] != 'present') if($_COOKIE ['testcookie10'] != 'present') if($_COOKIE ['testcookie11'] != 'present') if($_COOKIE ['testcookie13'] != 'present') if($_COOKIE ['testcookie12'] != 'present') { cookie_log(0, 'Cookies Disabled'); if (!isset($_GET['test'])) { header("Location: $ctestfile?mode=3"); } exit; } if($_COOKIE ['testcookie1'] == 'present') { cookie_log(1, 'temp-OK'); } else { cookie_log(1, 'temp-Fail'); } if($_COOKIE ['testcookie2'] == 'present') { cookie_log(2, 'perm-OK'); } else { cookie_log(2, 'perm-Fail'); } if($_COOKIE ['testcookie3'] == 'present') { cookie_log(3, 'perm-OK'); } else { cookie_log(3, 'perm-Fail'); } if($_COOKIE ['testcookie4'] == 'present') { cookie_log(4, 'temp-OK'); } else { cookie_log(4, 'temp-Fail'); } if($_COOKIE ['testcookie5'] == 'present') { cookie_log(5, 'perm-OK'); } else { cookie_log(5, 'perm-Fail'); } if($_COOKIE ['testcookie7'] == 'present') { cookie_log(7, 'perm-OK'); } else { cookie_log(7, 'perm-Fail'); } if($_COOKIE ['testcookie9'] == 'present') { cookie_log(9, 'temp-OK'); } else { cookie_log(9, 'temp-Fail'); } if($_COOKIE ['testcookie10'] == 'present') { cookie_log(10, 'perm-OK'); } else { cookie_log(10, 'perm-Fail'); } if($_COOKIE ['testcookie11'] == 'present') { cookie_log(11, 'perm-OK'); } else { cookie_log(11, 'perm-Fail'); } if($_COOKIE ['testcookie12'] == 'present') { cookie_log(12, 'temp-OK'); } else { cookie_log(12, 'temp-Fail'); } if($_COOKIE ['testcookie13'] == 'present') { cookie_log(13, 'perm-OK'); } else { cookie_log(13, 'perm-Fail'); } // Now clean up the cookies clearcookies(); if (!isset($_GET['test'])) { header("Location: $ctestfile?mode=3"); } exit; } ?> PHP Cookie Test '."\n \n\n"; if (false) { ?>

PHP Cookie Test -- Client Results

A Tool For Testing Your Browser's Cookie Capability By Chip Chapin

Contents

What's Here?

A painless evaluation of your browser's ability to set and return HTTP cookies.

“The Great PHP Cookie Test”

These tests and the idea behind them are derived from "The Great PHP Cookie Test" by Sean McLean at http://www.rnetwork.tv/cookietest/. I have basically just taken Sean's code and repackaged it as a client test to help diagnose cookie problems. Sean used it more to gather statistics on browser behaviour.

Your Client's Remote Address:
Your Browser's User Agent string:

There are 13 tested cookie setting procedures, as they appear in Sean McLean's original tests as of 11/29/01. For consistency, I've kept all the same tests, however, tests 6 and 8 incorrectly pass a string instead of the expiration time. This is essentially the same as passing an expiration time of zero. But many PHP coders seem to do this, so Sean included them in the list. Update: Tighter parameter checking in PHP 4.2.x now catches these errors, so tests 6 and 8 are shown, but are invalid.

$date = gmstrftime("%A, %d-%b-%Y %H:%M:%S",(mktime()+6400) );
$HTTP_HOST = ; // our server's hostname

??? -- 1:  header("Set-Cookie: testcookie1=present;");
??? -- 2:  header("Set-Cookie: testcookie2=present; expires=$date");
??? -- 3:  header("Set-Cookie: testcookie3=present; expires=$date; path=/");
4:    setcookie("testcookie4", "present");
5:    setcookie("testcookie5", "present", (time()+6400));
7:    setcookie("testcookie7", "present", (time()+6400), "/", "$HTTP_HOST");
9:    print "<meta http-equiv=\"Set-Cookie\" content=\"testcookie9=present\">\n";
10:   print "<meta http-equiv=\"Set-Cookie\" content=\"testcookie10=present; expires=$date\">\n";
11:   print "<meta http-equiv=\"Set-Cookie\" content=\"testcookie11=present; expires=$date; path=/\">\n";
12:   print "<script>document.cookie = 'testcookie12' + '=' + 'present';</script>\n";
13:   header("Set-Cookie: testcookie13=present; path=/; domain=$HTTP_HOST; expires=".gmstrftime("%A, %d-%b-%Y %H:%M:%S GMT",time()+9600));

YOUR Results

Below are the results for your current address and browser:

\n";
		fclose($fp);
//		unlink($clogfile);  // In this implementation, I use a unique logfile for each run.
	}
?>

Ideally, all methods should test 'OK' except for 6 and 8. It seems however that 1, 2, and 3 are also invalid. Apparently, setcookie() is your best bet.
To re-run the tests, click here.

Got Failures? Check Your System Date ...

Your client's system date should be close to "correct". Please compare it to our server's system date. If your system date is significantly wrong, then you will have problems with cookie expiration times. In fact, when I developed this test page to help me resolve a client problem, it turned out that the client's date was set 8 years in the future (2009 instead of 2001) so every cookie with an expiration date failed.

Our Server's System Date:
Your Client's System Date:

Need More Info About Cookies?

For information about setting cookies in PHP see the annotated online PHP Manual. Here are some other useful cookie resources:

RFC 2965 -- "HTTP State Management Mechanism"
The October 2000 internet standard for HTTP cookies.
Microsoft's Description of Cookies
An overview document with links to various resources, including relevant Microsoft support issues and external standards.

Source Code...

To see the source code for this page, click here.


Updated November 21, 2006