Thinkphp检测登录或操作超时(针对设置session有效期失效)

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">步骤如下:</span>

1.登录函数中存登录时间:

session('logintime',time());

2.在APP/Index/Common/common.php添加公共类:

class CheckAction extends Action {
        public function __construct() {
            parent::__construct();
            $this->checkAdminSession();
        }
        public function checkAdminSession() {
           // echo "happy";
            //设置超时为10分
            $nowtime = time();
            $s_time = session('logintime');
            if (($nowtime - $s_time) > 1800) {
                session('logintime',null);
                $this->error('当前用户未登录或登录超时,请重新登录', U('Admin/Index/index'));
            } else {
                session('logintime',$nowtime);
            }
        }
}

3.APP的每个需要检测的Action都继承上面的类:

例:

lass AnnouceAction extends CheckAction
{
   
    public function lists(){
		$username = session('agentName');
		//判断是否有输入密码;
		if(empty($username)){
		//如果为空跳回登录页;
			$this->redirect('QiXunAgent/Index/index');
		}
		$age=M('agentuser')->where(array('account'=>$username))->find();
		$m=M('announceforman');			 		
	 //加载分页类
		import('ORG.Util.Page');
	//计算记录总数
		$condition['managerID'] = 0;
		$condition['agentID'] = $age['id'];
		$count = $m->where($condition)->count();
	//实例化分页类
		$page = new Page($count,8);
	//设置主题
		$page->setConfig('header','');
		$page->setConfig('theme',"%totalRow% %header% 当前第 %nowPage% 页  共 %totalPage% 页 %upPage% %downPage% %first% %prePage% <span style='letter-spacing:5px'>%linkPage%</span> %nextPage% %end%");

	//设置超链接
		$this->show = $page->show();
			
		$data = $m->where($condition)->order('datetime desc')->limit($page->firstRow.",".$page->listRows)->select();	
		$this->assign('data',$data);
		$this->display();
	}
}


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值