嗨,我在 tuts 上的用户教程有问题...当我在登录表单中输入用户名和密码时,它返回为未经验证。我不确定发生了什么。这是代码
模型:user.php
<?php
class User extends CI_Model
{
// Create a user
function create_user($data){
$this->db->insert('users',$data);
}
// Login
function login($username,$password){
$where=array(
'username'=>$username,
'password'=>$password);
$this->db->select()->from('users')->where($where);
$query=$this->db->get();
return $query->first_row('array');
}
}
控制器:users.php
<?php
class Users extends CI_Controller
{
// Login Function
function login(){
$data['error']=0;
if ($_POST){
$this->load->model('user');
$username=$this->input->post('username',true);
$password=$this->input->post('password',true);
$user=$this->user->login($username,$password);
if(!$user){
$data['error']=1;
} else {
$this->session->set_userdata('userID',$user['userID']);
$this->session->set_userdata('user_type',$user['user_type']);
redirect(base_url().'index.php/posts/');
}
}
$this->template->load('layout/template', 'login', $data);
}
// Logout Function
function logout(){
$this->session->sess_destroy();
redirect (base_url()).'index.php/posts/';
}
}
查看:login.php
<h2>Login</h2>
<div class="row">
<div class="span12">
<?php if($error==1){ ?>
<p class="alert alert-error ">
Username/Password did not match...
</p>
<?php } ?>
<p>
<form action="<?=base_url()?>index.php/users/login" method="post">
<p><input class="span3" name="username" type="text" placeholder="Username"></p>
<p><input class="span3" name="password" type="password" placeholder="Password"></p>
<p><button class="btn btn-primary" type="submit">Login</button></p>
</form>
</p>
</div>
</div>
我已经彻底检查了它,但找不到任何东西......
任何帮助或信息将不胜感激,但请温柔,我是新手,哈哈...
克里斯