写一个thinkphp登录代码
时间: 2024-01-31 11:02:51 浏览: 77
thinkphp 登录验证 源代码
5星 · 资源好评率100%
<?php
namespace app\index\controller;
use think\Controller;
use app\index\model\User;
class Login extends Controller
{
public function index()
{
return $this->fetch();
}
public function login()
{
$username = input('post.username');
$password = input('post.password');
$user = User::where('username', $username)->find();
if (!$user) {
$this->error('用户名不存在!');
}
if ($user->password != md5($password)) {
$this->error('密码错误!');
}
session('user_id', $user->id);
session('username', $user->username);
$this->success('登录成功!', url('index/index'));
}
public function logout()
{
session(null);
$this->success('退出成功!', url('login/index'));
}
}
阅读全文