Forum Moderators: coopster
I am working through a tutorial to set a cookie that shows how many times a page has been visited. Here is the code that is before the <html> tag.
<?php
function visitNumber($pageVisits) {
echo '<h1>You have viewed this page '.$pageVisits.' time(s) </h1>';
}
$pageVisits = 1;
if(isset($_COOKIE['cookieVisits'])) {
$pageVisits = $_COOKIE['cookieVisits'] + 1;
}
setcookie('cookieVisits', '$pageVisits', time() +60*60*24*365);
?>
And here is the display in the <body>.
<?php
echo visitNumber($pageVisits);
?>