I'm using Codeigniter with Tank Auth authentication library. When a user reaches a page that requires a login and he has not logged in, he will be redirected to the login page.
Problem: On localhost, very frequently when I refresh the webpage, it can take up up to 30 sec before the page begins to load! Sometimes, after waiting for the page to load, it appears that I've got logged out as the page that loads is the login page which I have been redirected to. On the live server, the long delay before page load does not occur, but the user can get logged out seemingly randomly.
What's happening here? How can I find out which part of the code is causing the long load times? And what's causing the random logouts?
PHP Code (Controller)
function index() {
$this->load->module('auth');
if(!$this->auth->tank_auth->is_logged_in()) {
redirect('login');
}
// If user registered/logged in after landing on another page
if($this->session->userdata('entry_url')) {
$entry_url = $this->session->userdata('entry_url');
$this->session->unset_userdata('entry_url');
redirect($entry_url); // redirect back to entry url before registration/login
}
// Set User Session Variables
$user_id = $this->session->userdata('user_id');
$this->load->model('main_model');
$name = $this->main_model->get_user_first_last_name($user_id);
$this->session->set_userdata('first_name', $name['first_name']);
$this->session->set_userdata('last_name', $name['last_name']);
$this->load->view('main');
config.php
$config['sess_cookie_name'] = 'cisession';
$config['sess_expiration'] = 0;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['cookie_prefix'] = "";
$config['cookie_domain'] = "";
$config['cookie_path'] = "/";
$config['cookie_secure'] = FALSE;