Fun w/ Cookies

Recently started investigating how cookies worked for a upcoming project. Here is some of my research.

How To Create A Cookie

You can create a cookie using the following code:

//Set a value for the cookie
$value = 'I am a cookie!';

//Call setcookie php function
setcookie ("TestCookie", $value);

//print results to confirm
print "<p>The cookie says: " . $_COOKIE["TestCookie"] . "</p>";
			

Code In Action

The cookie says:

Print a list of cookies.

You can print a list of cookies using the following code:

foreach ($_COOKIE as $key => $value) {
	print "<strong>Key:</strong> " . $_COOKIE[$key] . " <strong>Value:</strong> " . $value . "<br>";
}

Code In Action

Key: nqiktpgasuagomke47mg8b58i6 Value: nqiktpgasuagomke47mg8b58i6