PHP判断用户是否已经登录实例分析

墨辰丷
发布: 2018-06-01 10:48:50
原创
3835人浏览过

这篇文章主要介绍了php判断用户是否已经登录的相关资料,非常不错,具有参考借鉴价值,需要的朋友可以参考下

1.

2.

1

2

3

4

5

<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.后台设置全局变量并查询用户信息

立即学习PHP免费学习笔记(深入)”;

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

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;

}

登录后复制

总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。

相关推荐:

PHP定义命令空间的几个注意点

PHP请求远程地址设置超时时间的解决方法

php通过PHPExcel导入Excel表格到MySQL数据库的简单实例

以上就是PHP判断用户是否已经登录实例分析的详细内容,更多请关注php中文网其它相关文章!

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号