Newsgroup: it.comp.www.php
Titolo: come si utilizza questo script?

ho trovato su internet questo script ma non ho ben capito come si fa a 
richiamare la pagina precedente. Cosa devo scrivere dentro il tag <a.href> ? 
ho provato brutalmente con <?php echo $referer; ?> ma mi va direttamente 
sulla home page.
grazie
<?
/*
 * PHP Freaks Code Library
 * 
http://www.phpfreaks.com/quickcode.php
 *
 * Title: setting a \"back\" link
 * Version: 1.0
 * Author: Rob Davies aka(crow)
 * Date: Thursday, 01/29/2004 - 11:09 AM
 *
 *
 *
 * NOTICE: This code is available from PHPFreaks.com code Library.
 *         This code is not Copyrighted by PHP Freaks.
 *
 *         PHP Freaks does not claim authorship of this code.
 *
 *         This code was submitted to our website by a user.
 *
 *         The user may or may not claim authorship of this code.
 *
 *         If there are any questions about the origin of this code,
 *         please contact the person who submitted it, not PHPFreaks.com!
 *
 *         USE THIS CODE AT YOUR OWN RISK! NO GUARANTEES ARE GIVEN!
 *
 * SHAMELESS PLUG: Need WebHosting? Checkout WebHost Freaks:
 *                 
http://www.webhostfreaks.com
 *                 WebHosting by PHP Freaks / The Web Freaks!
*/
// *    Description / Example:
// *
// *    This code will set a variable called $referer which contains the 
name of the previous page, so that you can provide the user with a \"back\" 
link without using JavaScript or $_SERVER[\'HTTP_REFERER\']. The real upside 
is that if you have many pages with a \"back\" link in a row, $referer 
always points to the one before it rather than swapping between the last two 
like a simple link to $_SERVER[\'HTTP_REFERER\']. It works by keeping a 
history of the last 10 pages visited by the user and not listing the same 
page twice in a row (so that if a page points to itself the \"back\" link 
will still always point to the previous page). The code block must be 
included at the start of every page, then setting the link is merely a 
matter of pointing to $referer.
?>
<?php
    function last_history_index ()
    {
        return sizeof ($_SESSION['page_history']) - 1;
    }
    function script_name ($full_path)
    {
        return substr ($full_path, strrpos ($full_path, '/') + 1);
    }
    $this_page = script_name ($_SERVER['REQUEST_URI']);
    if (!isset ($_SESSION['page_history']) and strpos ($this_page, 
'index.php') === false)
        $_SESSION['page_history'][0] = 'index.php';
    if (strpos ($_SESSION['page_history'][last_history_index ()], 
script_name ($_SERVER['PHP_SELF'])) === false)
        $_SESSION['page_history'][] = $this_page;
    else
        $_SESSION['page_history'][last_history_index ()] = $this_page;
    if ((sizeof ($_SESSION['page_history'])) > 10)
        array_shift ($_SESSION['page_history']);
    $this_page_index = last_history_index ();
    if ($this_page === $_SESSION['page_history'][$this_page_index - 2])
        unset ($_SESSION['page_history'][$this_page_index], 
$_SESSION['page_history'][$this_page_index - 1]);
    $referer = $_SESSION['page_history'][last_history_index () - 1];
?>

Marco ha scritto:

Non si capisce come chiami la funzione dal link.
A occhio mi pare che occorra dare un return di $referer alla funzione