views:

331

answers:

1

how to show Last Five Pages Visited Cookie with php jquery.

+2  A: 

Instead of using PHP and jQuery, this can be accomplished solely with PHP:

session_start();
if(empty($_SESSION['history']))
    $_SESSION['history'] = array($_SERVER['PHP_SELF']);
else {
    $_SESSION['history'][] = $_SERVER['PHP_SELF'];
    if(count($_SESSION['history']) > 5)
        array_shift($_SESSION['history']);
}

$_SESSION['history'] will be an array of URLs that the user has visited limited to 5.

mattbasta