在這裏我想用用戶名「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