程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> PHP判斷用戶是否已經登錄(跳轉到不同頁面或者執行不同動作),php跳轉

PHP判斷用戶是否已經登錄(跳轉到不同頁面或者執行不同動作),php跳轉

編輯:關於PHP編程

PHP判斷用戶是否已經登錄(跳轉到不同頁面或者執行不同動作),php跳轉


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.後台設置全局變量並查詢用戶信息

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'=>'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);
session('user_id',null);
header('Location:/Login/Login');
return false;
}
//超時的不能在這做,原因是存入session的值不變,如果用戶一直操作的話,而且只登陸一次,那麼就會出現問題
}
return true;
}

以上所述是小編給大家介紹的PHP判斷用戶是否已經登錄(跳轉到不同頁面或者執行不同動作),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對幫客之家網站的支持!

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved