PHP判断用户是否已经登录(跳转到不同页面或者执行不同动作)

前端之家收集整理的这篇文章主要介绍了PHP判断用户是否已经登录(跳转到不同页面或者执行不同动作)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1.

2.

PHP;">

3.后台设置全局变量查询用户信息

'System','Token'=>'wap','PostDetails'=>json_encode(array( ))); //通过curl的post方式发送接口请求 $curl=new CurlController(); $strs=$curl->SendCurl($system); $GLOBALS['system']=$strs['AcctDetails']; if(empty($user_id)){ return false; } setcookie("login_uid",$user_id,time() + 3600,"/",C('cookie_url')); setcookie("rdun",$this->authcode($user_id . "," . time(),"ENCODE"),C('cookie_url'));; $data=array( 'CmdId'=>'Individual','Token'=>session('token'),'PostDetails'=>json_encode(array( 'user_id'=>$user_id,))); //通过curl的post方式发送接口请求 $curl=new CurlController(); $str=$curl->SendCurl($data); $GLOBALS['userinfo']=$str['AcctDetails']; $newtoken=unserialize($str['AcctDetails']['token']); $oldtoken=unserialize(session('token')); if(!empty(session('token')) && !empty($str['AcctDetails']['token'])){ //用户不对 if($newtoken['user_id'] !== $newtoken['user_id']){ session('token',null); session('user_id',null); header('Location:/Login/Login'); return false; } //token不对 if($newtoken['time'] !== $oldtoken['time']){ session('token',null); header('Location:/Login/Login'); return false; } //超时的不能在这做,原因是存入session的值不变,如果用户一直操作的话,而且只登陆一次,那么就会出现问题 } return true; }

以上所述是小编给大家介绍的PHP判断用户是否已经登录跳转到不同页面或者执行不同动作)。编程之家 jb51.cc 收集整理的教程希望能对你有所帮助,如果觉得编程之家不错,可分享给好友!感谢支持

原文链接:https://www.f2er.com/php/18997.html

猜你在找的PHP相关文章