search

Home  >  Q&A  >  body text

Why can I access it directly even if I set the judgment?

<?php

namespace app\admins\controller;

use think\Controller;

use Util\data\Sysdb;

/**

*/

class BaseAdmin extends Controller

{//Account’s session data uses admin as the basis to determine whether the user is logged in. If there is no admin, no user will come in

public function __construct(){

parent::__construct();

//Assign sesson data to admin

$this->_admin = session ('admin');

if (!$this->_admin) {

// //If session has no value, it is judged that the user is not logged in and jumps to the login page

header('Location: /admins.php/admins/Account/login');

exit;

}

}

}


phpcn_u211985phpcn_u2119852405 days ago1630

reply all(8)I'll reply

  • 何人不识君

    何人不识君2018-09-01 15:26:02

    Change the browser and visit http://www.php.demo/admins.php/admins/Home/index

    reply
    0
  • ㅤ

    2018-08-23 10:04:40

    Solve it

    reply
    1
  • You bad bad

    You bad bad2018-07-18 15:53:16

    Add dump($this->_admin) in front of if and take a look

    reply
    0
  • phpcn_u211985

    After refreshing, it jumps back to the login page, but even if the login is successful, it cannot jump to it.

    phpcn_u211985 · 2018-07-18 20:35:00
  • anchu

    anchu2018-07-18 15:05:48

    Or delete the above and replace if directly

    if (!session('?admin'))

    reply
    0
  • phpcn_u211985

    Refresh and jump back to the login page, but the login page cannot be redirected even if the login is successful.

    phpcn_u211985 · 2018-07-18 17:04:01
    ㅤ

    The greetings here are in English.

    · 2018-08-23 09:38:29
  • anchu

    anchu2018-07-18 15:01:42

    How to use is_set when judging in if

    reply
    0
  • Cancelreply