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:
Save the session and modify the members() method. The code is as follows:
<?php Session::start(); if(isset($_SESSION['admin_name'])){ //session存在不用驗(yàn)證權(quán)限 $user = User::get([ 'user_name' => $_SESSION['admin_name'] ]); //更改數(shù)據(jù)庫(kù)信息,登錄了就根據(jù)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:
Database changes: