search

Home  >  Q&A  >  body text

After logging out, it still says please do not log in again.

7_NBRTP{1$X_EO@O~TT241N.pngARHSAL0C9(EE~`EIK3`F.pngSE]EP2]LB1P5~_5RL~@IC56.pngWhy 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');

}

}

}



?>


森2637 days ago1867

reply all(8)I'll reply

  • 山外山

    山外山2018-04-19 13:00:25

    if(is_null('USER_ID')){

    }

    if(!is_null('USER_ID')){

    }

    Remove the two 'USER_ID' single quotes


    reply
    1
  • 路过

    路过2017-10-26 15:38:17

    is_null is used to determine whether the variable is of type null

    Just change it to empty()

    reply
    0
  • 森

    Still not working

    · 2017-10-27 13:03:09
    yestrue

    I followed it and it turned out to be correct. I can only say that this video is correct except that it does not say use think\Session;. Let’s learn together, I’m on WeChat emaoqingshan

    yestrue · 2017-10-31 23:19:06
    路过

    You declared a constant and assigned a value, but the constant USER_ID was not processed when you exited.

    路过 · 2017-10-27 13:07:07
  • 森

    2017-10-26 13:00:16

    <?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)

    {

    //

    }

    }

    ##

    reply
    0
  • yestrue

    Let’s learn together, I’m on WeChat emaoqingshan

    yestrue · 2017-10-31 23:19:22
    阿拉坚果丶

    Add use think\Session; in Base.php All places where Session is used must be added.

    阿拉坚果丶 · 2018-03-04 18:56:08
  • Cancelreply