在这里我想用用户名“admin”和密码“管理员” 与表单验证并将这些值在会话 登录,但在数据库检查它是没有返回任何值? 我的控制器,验证用户名和密码是我有一个登录问题的用户名和密码是正确的
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->model('loginModel');
$this->load->helper('string');
$this->load->library("form_validation");
}
//login
public function index()
{
$this->load->view('login');
}
Public Function authentication()
{
$username=$this->input->post('username');
$password=$this->input->post('password');
$this->form_validation->set_rules("username","Username","required");
$this->form_validation->set_rules("password","Password","required");
if($this->form_validation->run() == FALSE)
{
echo "Error";
$this->session->set_flashdata('error','Invalid User Name or PASSWORD!');
redirect(site_url().'login');
} else {
$login_data = array(
"username"=>$username,
"password"=>$password
);
$authentication_response = $this->loginModel->user_authentication($login_data);
if($authentication_response)
{
$username = $authentication_response['UserName'];
$UserTypeId = $authentication_response['UserTypeId'];
//put the user info on session
$this->session->set_userdata("username", $username);
$this->session->set_userdata("UserTypeId", $UserTypeId);
if($UserTypeId == "1")
{
redirect("dashboard");
}
if($UserTypeId == "2")
{
redirect("dashboard");
}
if($UserTypeId == "3")
{
redirect("userPanel");
}
} else {
$this->session->set_flashdata("error", "Invalid User!!! Please check your user name or password correctly");
redirect("login");
}
}
}
function logout(){
$this->session->sess_destroy();
redirect(site_url().'login');
}
}//end of class
?>
我使用SQL Server 2008中 用户名= admin密码=管理员USERTYPEID = 1
其中loginModel-> user_authentication($ login_data)函数? – Gopalakrishnan
请提供您的loginModel代码进行审查。 –
<?PHP的 类LoginModel延伸CI_Model { \t公共函数user_authentication($ login_data) \t { \t \t $ result_set = $这个 - > DB-> get_where( “Tbl_UserList”,$ login_data); \t \t如果($ result_set-> NUM_ROWS()> 0) \t \t { \t \t \t返回$ result_set-> row_array(); \t \t} \t \t其他 \t \t { \t \t \t返回FALSE; \t \t} \t} } ?> – cks