[eluser]macleodjb[/eluser]
I have autoloaded my session control. I am running the following script in my login Controller.
Code:
<?php
class Login extends Controller {
function Login()
{
parent::Controller();
}
function index()
{
//if ($this->session->userdata('logged_in') == TRUE){
// redirect('login/login');
//}
$this->load->model('Main_model');
$this->load->library('validation');
$rules['email'] = "required|callback_check_email|callback_is_verified";
$rules['password'] = "required|callback_check_password";
$this->validation->set_rules($rules);
$fields['email'] = "Email Address";
$fields['password'] = "Password";
$this->validation->set_fields($fields);
$data['page_title'] = "";
$data['page_desc'] = "";
$data['page_keywords'] = "";
if ($this->validation->run() == FALSE){
$this->load->view('login/login', $data);
} else {
if($this->dologin()){
redirect('home');
} else {
$this->load->view('login/login', $data);
}
}
}
function check_email() {
$email = $this->input->post('email');
$user_query = $this->db->query("SELECT * FROM `user_admin` WHERE (`user_email` = '".$email."')");
if ($user_query->num_rows() > 0){
return true;
} else {
$this->validation->set_message('check_email', 'The email address you\'ve entered does not match our records');
return false;
}
}
function check_password() {
$email = $this->input->post('email');
$pass = $this->input->post('password');
$pass_query = $this->db->query("SELECT * FROM `user_admin` WHERE (`user_email` = '$email' && `user_password` = '$pass')");
if ($pass_query->num_rows() > 0){
return true;
} else {
$this->validation->set_message('check_password', 'The password you\'ve entered does not match our records');
return false;
}
}
function dologin() {
$member_info = $this->member_info($this->input->post('email'));
foreach ($member_info as $row){
$this->session->set_userdata('uid', $row['user_id']);
$this->session->set_userdata('user_name', $row['user_name']);
$this->session->set_userdata('user_type', $row['user_type']);
$this->update_login_time($this->input->post('email'));
//update_isactive_login($this->input->post('email'));
return true;
}
}
function is_verified($email) {
$verif_query = $this->db->query("SELECT * FROM `user_admin` WHERE (`user_email` = '" . $email . "')");
if ($verif_query->num_rows() > 0){
$row = $verif_query->row();
if($row->user_activate == 1){
return TRUE;
} else {
$this->validation->set_message('is_verified', 'You have not activated your account. Please check your email.');
return false;
}
} else {
return false;
}
}
function update_login_time($email) {
$update_login_query = $this->db->query("UPDATE `user_admin` SET `user_last_login` = NOW() WHERE (`user_email` = '".$email."') limit 1");
if ($update_login_query){
return TRUE;
} else {
return false;
}
}
function member_info($email) {
$mi_query = $this->db->query("SELECT * FROM `user_admin` WHERE (`user_email` = '" . $email . "')");
if ($mi_query->num_rows() > 0){
$test = $mi_query->row_array();
return $test;
} else {
return false;
}
}
}
When i get to the page i should get when login is successful it doesn't appear that the sessions has populated or it is dying some how. Is there something not being set somewhere?