Firstly, I want to tell you i have searched a lot but couldn't find a solution to it. Anyways first things first i am a newbie in CI and i have tried to make a login page built in CI using CI sessions. My Login Controller Function looks like this
//Validating login from ajax request
function validate_login() {
$email = $this->input->post('email');
$password = $this->input->post('password');
$credential = array('email' => $email, 'password' => sha1($password));
// Checking login credential for admin
$query = $this->db->get_where('admin', $credential);
if ($query->num_rows() > 0) {
$row = $query->row();
$_SESSION['admin_login'] = '1'; // I am using traditional PHP Session Global Variable for Setting Session Variable
$_SESSION['admin_id'] = $row->admin_id;
$_SESSION['login_user_id'] = $row->admin_id;
$_SESSION['name'] = $row->name;
$_SESSION['login_type'] = 'admin';
//echo $this->session->userdata('admin_login');exit; //This is printing the data fine
redirect(base_url() . 'index.php?admin/dashboard');
}
Now it gets redirected to Admin Controller Dashboard Function
/***ADMIN DASHBOARD***/
function dashboard()
{
echo "<pre>";
print_r($_SESSION); exit;
if ($this->session->userdata('admin_login') != 1)
redirect(base_url(), 'refresh');
$page_data['page_name'] = 'dashboard';
$page_data['page_title'] = get_phrase('admin_dashboard');
$this->load->view('backend/index', $page_data);
}
Output
Array
(
[__ci_last_regenerate] => 1530080373
)
My Autoload.php
$autoload['libraries'] = array('pagination', 'xmlrpc' , 'form_validation', 'email','upload','paypal','session','database');
Also i tried to load the session library on the constructer function of Admin
function __construct()
{
parent::__construct();
$this->load->database();
$this->load->model('Barcode_model');
$this->load->model('session');
/*cache control*/
$this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$this->output->set_header('Pragma: no-cache');
}
But nothing seems to work as i am unable to login and redirect to
if ($this->session->userdata('admin_login') != 1)
redirect(base_url(), 'refresh');
Config.php
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 7200;
$config['sess_regenerate_destroy'] = TRUE;
/*
|--------------------------------------------------------------------------
| Cookie Related Variables
|--------------------------------------------------------------------------
|
| 'cookie_prefix' = Set a cookie name prefix if you need to avoid collisions
| 'cookie_domain' = Set to .your-domain.com for site-wide cookies
| 'cookie_path' = Typically will be a forward slash
| 'cookie_secure' = Cookie will only be set if a secure HTTPS connection exists.
| 'cookie_httponly' = Cookie will only be accessible via HTTP(S) (no javascript)
|
| Note: These settings (with the exception of 'cookie_prefix' and
| 'cookie_httponly') will also affect sessions.
|
*/
$config['cookie_prefix'] = '';
$config['cookie_domain'] = 'localhost';
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;
/*
Is anything missing in my part to be set? Help Appreciated.