php返回上一页使用session存储上一页地址的方法

//返回上一页变量设置
$HTTP_REFERER = parse_url($_SERVER['HTTP_REFERER']);
if (! isset($_SESSION['ref']) || $HTTP_REFERER['path'] != $_SERVER['REDIRECT_URL']){
    $_SESSION['ref'] = array(
        'REDIRECT_URL'=>$_SERVER['REDIRECT_URL'],
        'HTTP_REFERER'=>"{$_SERVER['HTTP_REFERER']}"
    );
}

//html表单返回按钮
<input type="button" value="返回" onclick="location.href='<?=$_SESSION['ref']['HTTP_REFERER']?>'" />

你可能感兴趣的:(PHP,session,server,url,存储,redirect)