Use cookie to create page counter : Cookie « Cookie Session « PHP






Use cookie to create page counter


<?php
if (!isset($_COOKIE['visits'])) $_COOKIE['visits'] = 0;
$visits = $_COOKIE['visits'] + 1;
setcookie('visits',$visits,time()+3600*24*365);
?>
<html>
<head>
<title> Title </title>
</head>
<body>
<?php
if ($visits > 1) {
  echo("This is visit number $visits.");
} else { // First visit
  echo('Welcome to my Website! Click here for a tour!');
}
?>
</body>
</html>
           
       








Related examples in the same category

1.Using Multiple Values for a Cookie
2.Creating a Test Cookie
3.Setting and Printing a Cookie Value