Why does the message "Please do not log in again" appear after I log out? The session is not cleared? Unscientific
Base.php controller:
<?php
namespace app\admin\common;
use think\Controller;
use think\Session;
class Base extends Controller{
// The Base.php controller mainly completes three tasks:
// 1. Create a login flag constant,
// 2. Process the unlogged,
// 3. Process the logged in,
protected function _initialize(){
parent::_initialize();
// In the initialization method of the public controller, create a constant to determine whether the user is logged in or logged in
define('USER_ID ',Session::get('user_id'));
}
// Determine whether the user is logged in, call
at the background entrance protected function isLogin(){
// If the login constant is empty, it means there is no login.
if(is_null('USER_ID')){
$this->error('Not logged in, none Access...','login/index');
}
}
// If the user is already logged in, he will no longer be logged in
protected function alreadyLogin(){
//If the login constant is empty, it means there is no login
if(!is_null('USER_ID')){
$this- >error('Please do not log in again...','index/index');
}
}
}
?>
if(is_null('USER_ID')){
}
if(!is_null('USER_ID')){
}
Remove the two 'USER_ID' single quotes
is_null is used to determine whether the variable is of type null
Just change it to empty()
<?php
namespace app\admin\controller;
use app\admin\common \Base;
use think\Request;
use app\admin\model\Admin;
use think\Session;
class Login extends Base
{
// Render login interface
public function index()
{
$ This-& gt;
# Return $ this-& gt; view-& gt; fetch ('login');
##}## // Verify user identity
public function check(Request $request)
{
//Set the initial value returned
$status=0;
using using using ’ ’ ’ out ’ s ’ ’s ’ out out out ’s way out’s out’s’ out’s’ ’ through ’s ’ through ’ through ‐ through ‐ ‐‐‐ =$data['username'];
$password=md5($data['password']);
# $map=['username'=>$userName]; $admin=Admin::get($map); // Separate username and password Verification else if($admin->password!=$password){ $message='Password is incorrect'; $message='Verification passed, please log in to the backend'; 'last_time'=>time()]); . name:'user_info',value:$data); session::set('user_id',$userName); session::set('user_info',$data); } return ['status'=>$status,'message'=>$message];}
// Log out public function logout() { // session(null);Session::delete('user_id');
Session::delete('user_info');
$this->success('Registration successful, returning.. .','login/index');
//
}
## public function delete( $id) { // }}##