這篇文章主要介紹了PHP判斷使用者是否已經登入的相關資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
1.
2.
<if condition="$GLOBALS['userinfo']['user_id'] gt 0"><span class="help_wz"><a href="{$Think.config.VIP_URL}/Member/user_pwd/" style="color:#404958;">找回登入密碼</a></span><else/><span class="help_wz"><a href="/Login/FindPwd" style="color:#404958;">找回登入密碼</a></span></if>
3.後台設定全域變數並查詢使用者資訊
public function UserInfo($user_id){//查詢系統資訊$system=array('CmdId'=>'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"), time() + 3600,"/",C('cookie_url'));;$data=array('CmdId'=>'Inpidual','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);session('user_id',null);header('Location:/Login/Login');return false;}//逾時的不能在這做,原因是存入session的值不變,如果使用者一直操作的話,而且只登陸一次,那麼就會出現問題}return true;}
總結:以上就是本篇文的全部內容,希望能對大家的學習有所協助。