<?

// For Cookie count:
$expires = time() + 60 * 60 * 24; // Expires after one day.
$count = $_COOKIE['counter'];
if ($count == "")
	$count = 1;
else
	$count++;
setcookie('counter',$count, $expires);

// For Cookie user
setcookie('user','Mike Lewis');

// For Cookie multiple_values:
$array = array("Mike Lewis","SUNY Fredonia");
setcookie('multiple_values',serialize($array));


// For Cookie last_visit

$s = "Your last visit was on " . date('M d, Y, H:i:s T');
setcookie('last_visit',$s, $expires); 

// You may print the following for the user:

if (!empty($_COOKIE['counter']))
	echo "You've visited this homepage ". $_COOKIE['counter'] . " times so far.<br>\n";
if (!empty($_COOKIE['last_visit']))
	echo $_COOKIE['last_visit'], "<br>\n";

/* For printing the contents of the cookies (i.e. their values) 
(This printing is just an exercise and not intended for the user).
*/

$d = unserialize(stripslashes($_COOKIE['multiple_values']));

echo $_COOKIE['counter'], " visits.";

echo "<br>The contents of _COOKIE: <br>\n";

print_r($_COOKIE);

//print_r(unserialize(stripslashes($_COOKIE))); // NO, don't.

echo "<br>Before using unserialize and stripslashes for _COOKIE['multiple_values']: <br>\n";

print_r($_COOKIE['multiple_values']);

echo "<br>After using unserialize and stripslashes for _COOKIE['multiple_values']: <br>\n";

print_r($d);

echo "<br>";

echo serialize($array), "<br>";

?>
