源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-11-06 13:39 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:PHP判断用户是否已经登录(跳转到不同页面或者执行不同动作)
1. [img]http://files.jb51.net/file_images/article/201609/2016092214045622.png[/img] 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'=>'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判断用户是否已经登录(跳转到不同页面或者执行不同动作),希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程素材网网站的支持!
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部