我自己写了一个方法 如下 

$_SERVER[\'HTTP_REFERER\']

 可以查看上个页面传递过来的参数

<?php
header(\'content-type:text/html;charset=utf-8\');
include_once \'./lib/fun.php\';
judgeVx();
if (checkLogin()) {
    msg(1, \'您已登录\', \'index.php\');
}
//表单进行了提交处理
$gourl = \'index.php\';
if (empty($_POST[\'username\']) && strstr($_SERVER[\'HTTP_REFERER\'], $_SERVER[\'HTTP_HOST\'])) {
    $gourl = str_replace(getProtocol() . $_SERVER[\'HTTP_HOST\'], \"\", $_SERVER[\'HTTP_REFERER\']);
}

if (!empty($_POST[\'username\']) && !empty($_POST[\'password\'])) {
    $username = $_POST[\'username\'];
    $password = $_POST[\'password\'];
    $res = login($username, $password);

    if ($res == \"登录成功\") {
//        如果传递过来的域名 包含我们的域名 那么就替换掉 并且跳转
        header(\"Location:\" . $_POST[\'gourl\']);
    } else {
        msg(2, $res);

    }
}
?>

在登录的表单上多提交一个参数

 <input type=\"hidden\" name=\"gourl\" value=\"<?php echo $gourl ?>\">
            <button style=\"submit\" class=\"login_btn\">登 录</button>
function getProtocol()
{
    //主动判断是否HTTPS
    if (is_https()) {
        return \"https://\";
    } else {
        return \"http://\";
    }
}
function is_https()
{
    if (!empty($_SERVER[\'HTTPS\']) && strtolower($_SERVER[\'HTTPS\']) !== \'off\') {
        return true;
    } elseif (isset($_SERVER[\'HTTP_X_FORWARDED_PROTO\']) && $_SERVER[\'HTTP_X_FORWARDED_PROTO\'] === \'https\') {
        return true;
    } elseif (!empty($_SERVER[\'HTTP_FRONT_END_HTTPS\']) && strtolower($_SERVER[\'HTTP_FRONT_END_HTTPS\']) !== \'off\') {
        return true;
    }
    return false;
}

 

收藏 打印