按下“后退"按钮可重定向登录用户以注销? [英] Pressing back button redirects the logged user to log out?

查看:96
本文介绍了按下“后退"按钮可重定向登录用户以注销?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用用户名和密码的日志系统,在用户使用用户名和密码登录后,如果我按后退"按钮,它将重定向到我的登录页面. 如何在php中防止这种情况?

I have a logging system with username and password, after the user logged in with the username and password, and if i press the back button it redirects to me to the log in page. How to prevent this in php??

推荐答案

首先,您要使页面过期并阻止它们被浏览器缓存:

First you want to make the pages expire and prevent them from being cached by the browser:

<?
//Set no caching
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
header("Cache-Control: no-store, no-cache, must-revalidate"); 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>

第二,您应该检查用户是否已登录,如果已登录,则将其重定向回上一页,如下所示:

Second, you should check if the user is logged in, if so, redirect them back to the previous page, something like this:

// SET REFERRER

    function strleft($s1, $s2) { 
        return substr($s1, 0, strpos($s1, $s2));
    }   

    function selfURL() { 
        if(!isset($_SERVER['REQUEST_URI'])) { 
           $serverrequri = $_SERVER['PHP_SELF']; 
        }
        else { 
           $serverrequri = $_SERVER['REQUEST_URI']; 
        } 
        $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; 
        $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s; 
        $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); 
        $_SESSION['ref'] = $protocol."://>/".$_SERVER['SERVER_NAME'].$port.$serverrequri; 
    }               

selfURL();

然后

header("Location: " . $_SESSION['ref']);

这篇关于按下“后退"按钮可重定向登录用户以注销?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆