0

I want that after opening some page, redirect browser on previous page. I know about $_SERVER['HTTP_REFERER'] but this is not reliability right? There is better way for understand previous page url ?

4

1 回答 1

0

试试这个,它会将页面存储在会话中。有点像您最近查看过的内容。

session_start();

$_SESSION['pages'][] = $_SERVER['HTTP_REFERER'];


if ( Count ( $_SESSION['pages'] ) > 2 ){
 Array_Shift ( $_SESSION['pages'] );
}  

if ( Count ( $_SESSION['pages'] ) > 2 ){
 foreach ($_SESSION['pages'] as $key => $link)
{
if ($_SESSION['pages'][$key] == '')
{
    unset($_SESSION['pages'][$key]);
}
} 
}

//this will output previous page                                
echo $_SESSION['pages'][0];

可能有点矫枉过正,但您可以在过去的几个数组中保留页面历史记录

于 2012-12-18T17:13:47.777 回答