<?php require_once "naviguer.php"; require_once "../TME2/entete.php"; $cat = array('Londres' => 100, 'Madrid' => 200, 'Berlin' => 300); $saisie = isset($_POST['page']) ? $_POST['page'] : 1; $v = isset($_COOKIE['visite']) ? $_COOKIE['visite'] : 1; setcookie('visite', $v + 1); $title = "Page {$saisie}"; echo entete($title), "<body><h1>{$title}</h1>"; if (!is_numeric($saisie)) { echo "<div>Bon voyage pour " . $cat[$saisie] * ($v > 1 ? $v - 1 : 1) . "</div>\n"; } else { $c = ""; echo naviguer($cat, $saisie, $v, $c); } echo "</body></html>";
<?php require_once '../2/entete.php'; include 'naviguer.php'; function memorise_cookie() { if (!isset($_COOKIE['visite'])) { $v = 1; $f = 'COOKIE/' . md5(mt_rand() . $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']); } else { $f = 'COOKIE/' . $_COOKIE['visite']; $v = array_shift(file($f)); } if ($d = fopen($f, 'w')) { fputs($d, $v + 1); fclose($d); } setcookie('visite', $f); return $v; } $n = isset($_POST['page']) ? $_POST['page'] : 1; $titre = "Page {$n}"; $v = memorise_cookie(); echo entete($titre), "<body>\n<h1>", $titre, "</h1>\n"; if (!is_numeric($n)) { echo "<div>Bon voyage pour " . $bd[$n] * ($v > 1 ? $v - 1 : 1) . "€ </div>"; } else { $h = ""; echo naviguer($bd, $n, $v, $h); } echo "</body</html>\n";