Identifies user login status

A new status field is added to the think_user table in the database. After the user logs in, the database field is changed to indicate the login and online status.

After the user logs in successfully, add the following code:

微信图片_20180307170227.png

Save the session and modify the members() method. The code is as follows:

 $_SESSION['admin_name'] ]); //更改数据库信息,登录了就根据session把status改为1,退出或注销就改为0 Db::table('think_user')->where('user_name', $_SESSION['admin_name'])->update(['status' => 1]); }

In this way, after the user logs in, the user will Modify the session value of the database and change the status to 1 to indicate that you have logged in


##Modify the front-end display code The user login status will be displayed:

 

{$vo.user_id} 姓名:{$vo.user_name}{if $vo.status==1}在线{else}离线{/if}

{/volist}

Effect display:

gif5新文件 (13).gif

Database changes:

微信图片_20180307171108.png

Continuing Learning
||
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!