Welcome Guest, Not a member yet? Register   Sign In
CI_Session Acting Like Flashdata
#1

[eluser]SuperStromboli[/eluser]
Hi All,

I've written a basic auth system for my application that worked like a charm up until this morning.

When I go to login, it runs the auth and returns a valid record from the DB for the user in question. It's SUPPOSED to add the user object to the session, however when the login controller redirects to the homepage after auth, the session data I set no longer exists and I am therefore redirected back to the login form.

I have never made any change to the behavior of sessions throughout my project so I am beyond confused.

Has anyone encountered this before?

Many thanks!
#2

[eluser]CodeIgniteMe[/eluser]
Did you use a session database?
How long is the session set to expire?
Could it be a browser issue?
#3

[eluser]CodeIgniteMe[/eluser]
Did you use a session database?
How long is the session set to expire?
Could it be a browser issue?
#4

[eluser]SuperStromboli[/eluser]
It's occurring in both FF and IE. Here are my session settings:

Code:
$config['sess_cookie_name']        = 'ci_session';
$config['sess_expiration']        = 7200;
$config['sess_expire_on_close']    = FALSE;
$config['sess_encrypt_cookie']    = FALSE;
$config['sess_use_database']    = FALSE;
$config['sess_table_name']        = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent']    = TRUE;
$config['sess_time_to_update']    = 300;

As you can see, I do not store my sessions in a database.
#5

[eluser]n0xie[/eluser]
Are you sure your server time is correctly synchronised ?
#6

[eluser]SuperStromboli[/eluser]
System is indeed set to the proper date/time.
#7

[eluser]CodeIgniteMe[/eluser]
What is your development environment? Your CI Version? Your O.S.? HTTP Server? I believe your case is a browser issue. IE has confusions/issues with cookie names containing non-alphabetical characters (e.g. your underscore _). If this is the case, this has already been answered in another thread.
#8

[eluser]Vheissu[/eluser]
I am experiencing the exact same issue. I created a test controller setting a session value, reloading the page to see it's no longer set.

Try the following code in a controller called 'test.php' and reload the page a couple of times and see what happens.

Code:
<?php

class Test extends CI_Controller {
    
    public function index()
    {
        if ( $test = $this->session->userdata('test') )
        {
            echo "Session found, value stored was: ",$test;
            $this->session->unset_userdata('test');
        }
        else
        {
            echo "Empty session, setting a test variable";
            $this->session->set_userdata('test', 'value');
        }
    }
    
}
#9

[eluser]CodeIgniteMe[/eluser]
[quote author="Vheissu" date="1310665546"]I am experiencing the exact same issue. I created a test controller setting a session value, reloading the page to see it's no longer set.

Try the following code in a controller called 'test.php' and reload the page a couple of times and see what happens.

Code:
<?php

class Test extends CI_Controller {
    
    public function index()
    {
        if ( $test = $this->session->userdata('test') )
        {
            echo "Session found, value stored was: ",$test;
            $this->session->unset_userdata('test');
        }
        else
        {
            echo "Empty session, setting a test variable";
            $this->session->set_userdata('test', 'value');
        }
    }
    
}
[/quote]

I tried the code, and the output was:
Quote:Empty session, setting a test variable
and after one refresh,
Quote:Session found, value stored was: value
and after another refresh, the former result was outputted and so on...
#10

[eluser]Vheissu[/eluser]
Retry the same code again, but this time remove the unset_userdata line and see if the session value persists when you refresh.




Theme © iAndrew 2016 - Forum software by © MyBB