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:

<?php
Session::start();
if(isset($_SESSION['admin_name'])){
    //session存在不用验证权限
    $user = User::get([
        'user_name' => $_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:

<?php
{volist name="list" id="vo"}
<dt>
   <h3>{$vo.user_id} 姓名:{$vo.user_name}{if $vo.status==1}<span style="color: #008800">在线</span>{else}<span style="color: #880000">离线</span>{/if}</h3>
</dt>
{/volist}

Effect display:

gif5新文件 (13).gif

Database changes:

微信图片_20180307171108.png

Continuing Learning
||
<?php echo "登录状态表示";
submitReset Code