search

Home  >  Q&A  >  body text

Why is it that after the teacher typed this code to set the user session value, there was no response when I clicked the login button and I couldn’t log in?

  Session::set('user_id',$user->id);

  Session::set('user_info',$user->getData());


人生如戏人生如戏2439 days ago1590

reply all(5)I'll reply

  • David

    David2018-10-16 16:34:31

    tp5.1 changed the reference path to: use think\Facade\Session;

    reply
    0
  • 每一天,为明天

    每一天,为明天2018-05-05 17:23:19

    Print it first to see if you can output the data you submitted and see if the data is correct

    reply
    0
  • 人生如戏

    人生如戏2018-05-05 17:13:10

    user.php

    ....

    use think\Request;

    use app\index\model\User as UserModel;

    use think\Session;

    ....

    public function checkLogin(Request $request)

    {

    //Initial return parameters

    $status = 0;

    $result = '';

    $data = $request -> param();

    //Create validation rules

                      $rule = [                                                                                                                                                               ’ ’ ’ s ’ s ’ s                     ’ ’ ’ s ’ ’ s ’ ’ s ‐ ‐ ‐ ‐ ‐ ‐ to 'name|Username' => 'require',

    ##                      ## 'Veritfy | Verification Code' = & GT; 'Require | CAPTCHA',

    ##;

    ## // ## $ msg = [

    # 'name' = & gt; ['Require' = & gt; 'Username cannot be empty, please check'],

    'password' = & gt; [[[[[[[[ 'require'=>'The password cannot be empty, please check'],


    'veritfy' =>['require'=>'The verification code cannot be empty, please check',

                             'captcha'=>'Verification code error, please check'

                                                                                                                                $result = $this -> validate($data,$rule,$msg);

    ##                                                                                                                                                                                                                                                ($ Result === True)

    # {

    // Construction query condition

    $ map = [

    # 'name' = & gt; $ data ['name'],

    # 'Password' = & GT; md5 ($ data ['password']

    ##] [[

    $ User = Usermodel :: get ($ map);

    ## counter ($ user == null) {


    $ result = 'No found! ';

          }else{

                $status = 1;

                  $result = 'Verification passed, click [OK] to enter!';

                //设置用户的Session值

                //Session::set('user_id',$user->id);//用户ID

              //  Session::set('user_info',$user->getData());//获取用户所有信息


              Session::set('user_id,$user[id]');

              Session::set('user_info.name',$user['name']);

            

              }

            }

            return ['status'=>$status,'message'=>$result,'data'=>$data];

        }

    header.htnl

    <li>超级管理员</li>

    <li class="dropDown dropDown_hover"> <a href="#" class="dropDown_A">{:session('user_info.name')} <i class="Hui-iconfont"></i></a>

    <ul class="dropDown-menu menu radius box-shadow">

    <li><a href="{:url('user/logout')}">退出</a></li>


    reply
    0
  • 每一天,为明天

    每一天,为明天2018-05-05 17:07:02

    Post all the code! !

    reply
    0
  • 人生如戏

    user.php .... use think\Request; use app\index\model\User as UserModel; use think\Session; .... public function checkLogin(Request $request) { //Initial return parameters $status = 0; $result = ''; $data = $request -> param(); //Create validation rules $rule = [ 'name|username' =>'require', 'password|password' => 'require', 'veritfy|Verification code' =>'require|captcha', ]; //Create verification failure information $msg = [ 'name' =>['require'=>'Username cannot be empty, please check'], 'password' =>['require'=>'Password cannot be empty, please check'], 'veritfy' =>['require'=>'Verification code cannot be empty, please check', 'captcha'=>'Verification code error, please check' ], ]; //Perform simple verification $result = $this -> validate($data,$rule,$msg); //If verification is successful, execute if($result === true) { //Construct query conditions $map = [ 'name'=>$data['name'], 'password'=>md5($data['password']) ]; //Query user information $user = UserModel::get($map); if($user == null){ $result = 'The user was not found! '; }else{ $status = 1; $result = 'Verification passed, click [OK] to enter!'; //Set the user's Session value //Session::set('user_id',$user->id);//User ID // Session::set('user_info',$user->getData());//Get all user information Session::set('user_id,$user[id]'); Session::set('user_info.name',$user['name']); } } return ['status'=>$status,'message'=>$result,'data'=>$data]; } header.html <li>Super Administrator</li> <li class="dropDown dropDown_hover"> <a href="#" class="dropDown_A">{:session('user_info.name')} <i class="Hui-iconfont">& #xe6d5;</i></a> <ul class="dropDown-menu menu radius box-shadow"> <li><a href="{:url('user/logout')}">Exit</a></li>

    人生如戏 · 2018-05-05 17:11:56
  • Cancelreply