<?php

$top='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head><title></title><meta http-equiv="content-type"
content="text/html; charset=UTF-8"/>
</head><body><div>';

$bottom='</div><p>
<a href="http://validator.w3.org/check?uri=referer">
<img style="border: 0pt" src="/valid-xhtml10.png"
     alt="Valid XHTML 1.0!" height="31" width="88" />
</a></p></body></html>';

// has to be done before any print
session_start();
$current=time();
if(isset($_SESSION['last_click'])) {
  $passed=$current-$_SESSION['last_click'];
  $duration=pretty_duration($passed);
  $to_print="You last visited $duration ago.\n";
  $_SESSION['last_click']=$current;
}
else {
  $to_print="This is your first visit.\n";
  $_SESSION['last_click']=$current;
}

function pretty_duration($sec) {
  if($sec < 60) {
    return "$sec seconds";
  }
  if($sec == 60) { 
    return "one minute"; 
  }
  if($sec < 120) { 
    $rest=$sec % 60;
    return "one minute and $rest seconds"; 
  }
}



// print all in one go
print "$top\n$to_print\n$bottom";


?>