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();
}
}
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇: thinkphp之Ajax提交和返回
- 下一篇: thinkphp之URL,跳转和重定向
