Welcome Guest, Not a member yet? Register   Sign In
Changing a config variable after its set in config?
#1

[eluser]delay[/eluser]
I am using ci sessions and I am trying to setup a remember me feature in my login. So in the config file I have
Code:
$config['sess_expiration'] = 7200
; The default setting of 7200 is good if a user doesn't select remember me. If they select remember me I would like to change it in the program to 0
Code:
$config['sess_expiration']=0
. How can I change a config setting from within a model?

Code:
if ($rememberme) {
        $config['sess_expiration'] = 0; //doesn't work
        }


Thanks for any help.
#2

[eluser]xwero[/eluser]
Code:
$this->config->set_item('sess_expiration',0);
#3

[eluser]delay[/eluser]
Thanks very much for the info... That does seem to reset the config variable. However it doesn't seem to be working. I can set it and check it and it does change from 7200 to 0 but when I set my session it always seems to keep the 7200 timeout period (2 hours) sent initially in the config file.

Code:
if ($rememberme) {
$val1 = $this->config->item('sess_expiration'); // $val1 is 7200
$this->config->set_item('sess_expiration',0);
$val2 = $this->config->item('sess_expiration'); // $val2 is now 0
}
//Then I set my session
$this->session->set_userdata(array('Id'=>$row->Id)); /*but it always has the cookie set to expire in 2 hours regardless of what I try to reset the config variable to.*/

I am wondering since I autoload my sessions has the config variable already been setup for creating sessions so even when I change it, it doesn't change since its loaded?
#4

[eluser]delay[/eluser]
That was the trouble. When I turn off auto loading and then load the session library right before creating the session but after resetting the config variable then it changes correctly.

Anyway thanks for the initial help!
#5

[eluser]CarNinja[/eluser]
[quote author="delay" date="1201359727"]That was the trouble. When I turn off auto loading and then load the session library right before creating the session but after resetting the config variable then it changes correctly.

Anyway thanks for the initial help![/quote]

I'm posting this solution for anyone who may be trying to figure this out in the future...

Code:
if( $bRemember )
{
    // Change the config setting
    $this->config->set_item('sess_expiration',0);

    // Force the Session class to recapture global settings by calling it's constructor
    $this->session->CI_Session();
}
#6

[eluser]Ignacio[/eluser]
This is actually working good, but calling again the class is not a waste of resources? There is any better solution for this? Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB