Cookie example


The simplest example of using a session and cookies, for example, to calculate page traffic by a specific user. When the user first visits, a message is displayed that he is here for the first time, and on subsequent visits, the user is told that he has already been here and the number of his visits is displayed, and a page refresh link is generated.

test tkest
<?php session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">
<html xmlns="" xml:lang="en">
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
  <link rel="icon" href="icon.png"/>
  <title>Cookie example</title>
  <h2 style="text-align:center;">Cookie example</h2>
   if (!isset($_SESSION['counter']))
    echo '<center>This is your first visit.</center>';
    $_SESSION['counter'] = 1;
    echo '<p style="text-align:center;">You've been here before ',$_SESSION['counter'],' times.</p>';
   $url = $_SERVER['PHP_SELF'];
   $sid = sid;
   if (isset($sid) && $sid) $href = $url.'?'.$sid;
   else $href = $url;
   echo '<p style="text-align:center;"><a href="',$href,'">Visit us again!</a></p>';

Last in our blog

Internet Marketing