Tools, FAQ, Tutorials:
Testing Cookies on a Web Server in PHP
How To Test Cookies on a Web Server in PHP?
✍: FYIcenter.com
If you want to test cookies with a browser, you need to run a Web server locally, or have access to a Web server remotely. Then you can copy the following PHP cookie test page, setting_receiving_cookies.php, to the Web server:
<?php
setcookie("LoginName","FYICenter");
setcookie("PreferredColor","Blue");
print("<pre>\n");
print("2 cookies were delivered.\n");
if (isset($_COOKIE["LoginName"])) {
$loginName = $_COOKIE["LoginName"];
print("Received a cookie named as LoginName: ".$loginName."\n");
} else {
print("Did not received any cookie named as LoginName.\n");
}
$count = count($_COOKIE);
print("$count cookies received.\n");
foreach ($_COOKIE as $name => $value) {
print " $name = $value\n";
}
print("</pre>\n");
?>
If you open this PHP page with a browser as http://localhost/setting_receiving_cookies.php, you will get:
2 cookies were delivered. Did not received any cookie named as LoginName. 0 cookies received.
"0 cookies received" is because there was no previous visit from this browser. But if you click the refresh button of your browser, you will get:
2 cookies were delivered. Received a cookie named as LoginName: FYICenter 2 cookies received. LoginName = FYICenter PreferredColor = Blue
⇒ What Is a Persistent Cookie in PHP
⇐ Receiving a Cookie from the Browser in PHP
2016-11-04, ∼2115🔥, 0💬
Popular Posts:
How to use urllib.parse.urlencode() function to encode HTTP POST data? My form data has special char...
How to use the "set-variable" Policy Statement to create custom variables for an Azure API service o...
How to detect errors occurred in the json_decode() call? You can use the following two functions to ...
What is EPUB 2.0 Metadata "dc:creator" and "dc:contributor" elements? EPUB 2.0 Metadata "dc:creator"...
How to detect errors occurred in the json_decode() call? You can use the following two functions to ...