Welcome Guest, Not a member yet? Register   Sign In
Session timing out intermittently
#1

[eluser]bikuta[/eluser]
For some reason my site does seem to want to remember session data for some users.i.e., they log in and see the home page, but once they click on another link, they are immediately logged out, i.e., they get redirected to the login page.

This has not been happening for me and none of our testing have encountered this. This also affects both FF and IE.

Any ideas what it could be? What kind of things should I check?

This is what my session variables look like:
Code:
$config['sess_cookie_name']        = '_session';
$config['sess_expiration']        = -1;
$config['sess_encrypt_cookie']    = TRUE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']        = '_sessions';
$config['sess_match_ip']        = TRUE;
$config['sess_match_useragent']    = TRUE;
$config['sess_time_to_update']  = 300;

Expiration is -1 because I used the mod to expire cookies on browser close. I'm using CI 1.6.3

I also have this check in each of my controllers:
Code:
if ((time() - $this->session->userdata('last_activity')) > 3600) {
            $this->session->sess_destroy();
            redirect('');
        }

This is to so that they can't keep the session open by leaving their window open.
#2

[eluser]indocoder[/eluser]
Enlighten me... so your app running well on your development phase. or not?
Have you check that session library is already loaded?
#3

[eluser]bikuta[/eluser]
yes it's running well on my development machine

the session library is set to autoload
#4

[eluser]indocoder[/eluser]
ok, check your server configuration. especially for the session variable.
I dont believe CI responsible for this error.
#5

[eluser]Sumon[/eluser]
would you please try something like
Code:
$this->session->set_userdata('all_session_variables','');
$this->session->set_userdata('all_session_variables','');
and while you check your login use
Code:
if($this->session->userdata('login')=="")
// Redirect to login
else
//Go for further activities..
instead of
Code:
$this->session->sess_destroy();
#6

[eluser]bikuta[/eluser]
Why can't I use:
Code:
$cookie = array('UserRole' => $user->UserRoleId, 'Username' => $user->Username);
$this->session->set_userdata($cookie);
#7

[eluser]Sumon[/eluser]
Ops!!! i forget to include.
May be a way.... use this code to checking......
Code:
if($this->session->userdata("Username")!=""
//Logged in action
instead of destroy session. If you not assign a session variable (say Username) you are permitted to check using
Code:
if($this->session->userdata("Username")!=""
#8

[eluser]bikuta[/eluser]
Can't I use
Code:
if (!$this->session->userdata('Username'))
#9

[eluser]Sumon[/eluser]
! is associated with false whereas "" empty value(by default set automatically)
Code:
if($this->session->userdata("Username")!=""
#10

[eluser]indocoder[/eluser]
Quote:Note: Session cookies are only updated every five minutes to reduce processor load. If you repeatedly reload a page you'll notice that the "last activity" time only updates if five minutes or more has passed since the last time the cookie was written.


Code:
if ((time() - $this->session->userdata('last_activity')) > 3600) {
            $this->session->sess_destroy();
            redirect('');
        }

please print_r all your session data.




Theme © iAndrew 2016 - Forum software by © MyBB