我无法对我的登录进行身份验证,我不知道为什么,我的表单也没有“提交”!
控制器登录.php
<?php
class Login extends CI_Controller
{
public function index(){
$this->load->view('admin/login');
}
public function auth(){
//Model User
$this->load->model('user_model');
//Post
$login = $this->input->post('username');
$senha = $this->input->post('password');
$query = $this->user_model->validate($login, $senha);
if($query){
$data = array(
'username' => $this->input->post('username'),
'logged' => true
);
$this->session->userdata($data);
redirect('admin/index');
}else{
redirect('admin/ease');
$this->session->set_flashdata('error_login', 'You dont have permission for access this area! Please, contact the support!');
}
}
}
?>
模型 user_model.php
<?php
class User_model extends CI_Model
{
public function validate($login, $password){
$this->db->where('username',$login);
$this->db->where('password',$password);
$this->db->where('status','1');
$query = $this->db->get('usuario');
if($query->num_rows == 1){
return true;
}else{
return false;
}
}
//Verifica se o Usuario está logado
public function logged(){
$logged = $this->session->userdata('logged');
if(!isset($logged) || $logged != true){
echo 'Voce nao tem permissao para entrar nessa pagina. <a href="http://localhost/curriculo/login">Efetuar Login</a>';
die();
}
}
}
?>
查看 login.php
<?php
echo form_open(site_url('login/auth'));
echo "<br>";
echo "<br>";
echo form_label('Username', 'username');
echo form_input('username', '');
echo "<br>";
echo form_label('Password', 'password');
echo form_password('password', '');
echo "<br>";
echo form_submit('submit', 'Login');
echo $this->session->flashdata('error_login');
form_close();
?>
我在看一个朋友的表格,他使用 div 而不是使用 CI 的预定义函数,它起作用了!