PHP (thinkphp)后台设置验证登陆(所有)和登陆超时的方法
因为我是使用的TP 框架的,所以可以使用继续公共类的形式来实现方法的公用。其中的包括一些验证等方法。
下面讲下实现页面的验证登陆的方法:
public function _initialize() { header("Content-Type:text/html; charset=utf-8"); if (!isset($_SESSION["user"])) { echo "<script>alert("请先登陆!");document.location.href="/index.php/Home/Login/login";</script>";} $this->checkAdminSession();
}
这个就是实现登陆后的超时验证的代码: public function checkAdminSession() { // 设置超时为10分 $nowtime = time(); $s_time = $_SESSION["logintime"]; if (($nowtime - $s_time) > 6000000) { session_unset(); session_destroy(); echo "<script>alert("当前用户登录超时,请重新登录!");document.location.href="/index.php/Home/Login/login";</script>"; $_SESSION["logintime"] = $nowtime; } }
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。