Welcome Guest, Not a member yet? Register   Sign In
How does sessions in CI retreived?
#1

[eluser]rameners[/eluser]
I have this class Test, What I want to do is retrieve the value of username1 on the session. When I call the method viewMySession() it does not echo the value of the session username1. How to access the value that was set on the session, does it something to do with cookies? If then will anyone would like to share how to do it. Thanks and more power.

Note: session class is autoloaded.

Code:
class Test extends Controller {

    function Test() {
        parent::Controller();
    }
    
        //initialize the session
    function index() {        
        $this->session->set_userdata(array('username1' => '1'));
    }

        //print the value
    public function viewMySession() {
        echo $this->session->userdata('username1');
    }
    
        //destroy the session
    public function destroyMySession() {
        $this->session->sess_destroy();
    }
}
#2

[eluser]TheFuzzy0ne[/eluser]
Assuming you are navigating to the default index() method first, which sets the username1 value, you're example works fine for me. Have you changed you're cookie settings at all in your config.php? In most cases, you should never have to change the configuration.
#3

[eluser]Dam1an[/eluser]
CI session use cookies, so make sure you have those enabled for this site

If you use the profiler extension I mentioned in this thread you can view session data in the profiler (very useful Smile) so you'll know if it even gets written or not
#4

[eluser]rameners[/eluser]
[quote author="TheFuzzy0ne" date="1242831896"]Assuming you are navigating to the default index() method first, which sets the username1 value, you're example works fine for me. Have you changed you're cookie settings at all in your config.php? In most cases, you should never have to change the configuration.[/quote]

Thanks for the reply. BTW, it doesn't run on Safari, Chrome and IE, only firefox does the job. Is there something I miss in the configuration? I didn't modify the session class or anything.Is it a browser issue or just my pc has a virus? Below is my configuration for the cookie

Code:
$config['sess_cookie_name']        = 'ci_session';
$config['sess_expiration']        = 7200;
$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;




Theme © iAndrew 2016 - Forum software by © MyBB