使用PHP怎么判斷用戶的登錄狀態(tài)?針對(duì)這個(gè)問題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問題的小伙伴找到更簡(jiǎn)單易行的方法。
1.
2.
<if condition="$GLOBALS['userinfo']['user_id'] gt 0"> <span class="help_wz"><a href="{$Think.config.VIP_URL}/Member/user_pwd/" >找回登錄密碼</a></span> <else/> <span class="help_wz"><a href="/Login/FindPwd" >找回登錄密碼</a></span> </if>
3.后臺(tái)設(shè)置全局變量并查詢用戶信息
public function UserInfo($user_id){ //查詢系統(tǒng)信息 $system=array( 'CmdId'=>'System', 'Token'=>'wap', 'PostDetails'=>json_encode(array( ))); //通過curl的post方式發(fā)送接口請(qǐng)求 $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'=>'Individual', 'Token'=>session('token'), 'PostDetails'=>json_encode(array( 'user_id'=>$user_id, ))); //通過curl的post方式發(fā)送接口請(qǐng)求 $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'])){ //用戶不對(duì) if($newtoken['user_id'] !== $newtoken['user_id']){ session('token',null); session('user_id',null); header('Location:/Login/Login'); return false; } //token不對(duì) if($newtoken['time'] !== $oldtoken['time']){ session('token',null); session('user_id',null); header('Location:/Login/Login'); return false; } //超時(shí)的不能在這做,原因是存入session的值不變,如果用戶一直操作的話,而且只登陸一次,那么就會(huì)出現(xiàn)問題 } return true; }
關(guān)于使用PHP怎么判斷用戶的登錄狀態(tài)問題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識(shí)。
文章名稱:使用PHP怎么判斷用戶的登錄狀態(tài)-創(chuàng)新互聯(lián)
當(dāng)前鏈接:http://vcdvsql.cn/article2/eidoc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷、網(wǎng)站維護(hù)、網(wǎng)站設(shè)計(jì)、網(wǎng)站收錄、做網(wǎng)站、網(wǎng)頁設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容