摘要:<?php namespace app\admin\controller; use think\Controller; use think\Facade\Session; class Common extends Controller { public function&
<?php
namespace app\admin\controller;
use think\Controller;
use think\Facade\Session;
class Common extends Controller
{
public function __construct()
{
parent::__construct();
if(!session::has('username')){
$this->error('您还未登录,请先登录。','login/login');
}
}
}上面是验证Session文件
<?php
namespace app\admin\controller;
use think\Controller;
use think\Facade\Request;
use think\Facade\Session;
use app\admin\model\user as UserModel;
class Login extends Controller
{
public function login()
{
return $this->fetch();
}
public function DoLogin()
{
$login_user = Request::param();
$user = UserModel::field(['username','passwd'])->where('username',$login_user['username'])->find();
$login_user['passwd'] = md5($login_user['passwd']);
if($user != true)
{
return ['res' => false, 'msg' => '用户名不存在'];
}
elseif($login_user['passwd'] != $user['passwd'])
{
return ['res' => false, 'msg' => '你输入密码错误'];
}else
{
Session::set('username',$login_user['username']);
return ['res' => true, 'msg' => '登录成功'];
// session_start();
// $_SESSION['username'] = $login_user['username'];
}
}
public function LoginOut()
{
Session::delete('username');
$this->redirect('login/login');
}
}
批改老师:韦小宝批改时间:2019-01-09 15:12:08
老师总结:现在的session写入可以写入成功了吧 写的很不错 继续加油吧