Recall: Setting cookies in PHP

setcookie("name", "value");
...
$variable = $_COOKIE["name"];   # retrieve value of cookie later
setcookie("username", "martay");
setcookie("age", 19);
...
if (isset($_COOKIE["username"])) {
	$username = $_COOKIE["username"];
	print("Welcome back, $username.\n");
}

Exercise : Longcat Count (by Phil Sheperd)

top
bottom

Use a cookie (slides) to count the number of times the user has viewed longcat.php. Display this count to the user on the page, e.g. "You have visited 7 time(s)." (sample solution) For added challenge:

Exercise Solution