您的位置:首页 > 编程语言 > PHP开发

PHP (thinkphp)后台设置验证登陆(所有)和登陆超时的方法

2017-07-19 10:58 369 查看
因为我是使用的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;
        }
    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: