php5 session丢失,thinkphp5 登陆以后 session 就失效了

14

251 天前

```

/**

* 用户登录

*/

public function login(Request $request)

{

// 用户已经登陆直接跳转到首页

$admin_info = Session::get('admin_info');

if(!empty($admin_info)){

$this->redirect('index/index');

}

if($request->isAjax())

{

$phone = $request->param('phone','','trim,strip_tags,htmlspecialchars');

$password = $request->param('password','','trim,strip_tags,htmlspecialchars');

$captcha = $request->param('captcha','','trim,strip_tags,htmlspecialchars');

if(!captcha_check($captcha)){

return responseJson('400', '验证码错误');

}

$admin_info = \app\manager\model\Admin::alias('a')

->join('role r', 'a.role = r.id')

->where('phone', $phone)

->field('a.*,r.role_name,auth_group')

->find();

if(!$admin_info){

return responseJson('400','账户信息不存在');

}

if($admin_info['is_delete'] || $admin_info['is_freeze']){

return responseJson('400','账号异常');

}

if(!password_verify($password,$admin_info['password'])){

return responseJson('400','账号密码不匹配');

}else{

$data = [

'login_ip' => get_real_ip(),

'login_time'=>time()

];

// 更新登录的 ip 地址和登录时间

$res = Db::name('admin')->where('phone',$phone)->data($data)->update();

if(!$res){

return responseJson('500','服务器错误');

}

unset($admin_info['password']);

$admin_info->auth_rule = \app\manager\model\Admin::getUserAuth($admin_info->auth_group);

Session::set('admin_info',$admin_info);

return responseJson('200','登陆成功');

}

}else{

return $this->fetch();

}

}

/**

* 退出登录

* @param

* @return

*/

public function logout()

{

Session::delete('admin_info');

return $this->redirect('account/login');

}

```

```

// +----------------------------------------------------------------------

// | ThinkPHP [ WE CAN DO IT JUST THINK ]

// +----------------------------------------------------------------------

// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.

// +----------------------------------------------------------------------

// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )

// +----------------------------------------------------------------------

// | Author: liu21st

// +----------------------------------------------------------------------

// +----------------------------------------------------------------------

// | 会话设置

// +----------------------------------------------------------------------

return [

'id' => '',

// SESSION_ID 的提交变量,解决 flash 上传跨域

'var_session_id' => '',

// SESSION 前缀

'prefix' => 'think',

// 驱动方式 支持 redis memcache memcached

'type' => '',

// 是否自动开启 SESSION

'auto_start' => true

];

```

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值