I Have created a controller named Admin.php
class Admin extends CI_Controller {
function __construct(){
parent::__construct();
}
public function index($msg = NULL) {
$data['msg'] = $msg;
$this->load->view('pages/sign-in');
}
public function process(){
// Load the model
$this->load->model('admin/Admin_model');
// Validate the user can login
$result = $this->Admin_model->validate();
// Now we verify the result
if(! $result){
// If user did not validate, then show them login page again
$msg = '<font color=red>Invalid username and/or password.</font><br />';
$this->index($msg);
}else{
// If user did validate,
// Send them to members area
redirect(base_url().'home');
}
}
and model is
class Admin_model extends CI_Model
{
function __construct()
{
// Call the Model constructor
parent::__construct();
$this->load->database();
}
public function validate(){
// grab user input
$username = $this->security->xss_clean($this->input->post('username'));
$password = $this->security->xss_clean($this->input->post('password'));
// Prep the query
$this->db->where('username', $username);
$this->db->where('password', $password);
// Run the query
$query = $this->db->get('wc_watchconnect_adminlogin');
// Let's check if there are any results
if($query->num_rows == 1)
{
// If there is a user, then create session data
$row = $query->row();
$data = array(
'userid' => $row->id,
'username' => $row->username,
'validated' => true
);
$this->session->set_userdata($data);
return true;
}
// If the previous process did not validate
// then return false.
return false;
}
}
one more controller is home
class Home extends CI_Controller {
function __construct(){
parent::__construct();
$this->check_isvalidated();
}
public function index(){
$this->load->view('pages/index');
}
private function check_isvalidated(){
if(! $this->session->userdata('validated')){
redirect(base_url().'index.php/admin');
}
}
}
?>
in this $result is showing null value it is blank while i have username=admin and password=admin in database ... values are not getting fetch in $result pls help me to get rid out of this... thanks in advance
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…