Smart session with Codeigniter

Asked

Viewed 1,049 times

1

I have an application developed with Codeigniter, PHP and Mysql. The user’s session has always been treated according to the Codeigniter standard, but now I need the session to be more restrictive, operating in a manner analogous to an internet banking session, expiring in seven minutes (420 seconds) inactivity, and with each client request with the server these seven minutes are renewed.

I don’t know if natively just setting parameters Codeigniter supports this way of storing the session, but I haven’t been able to represent this way of working.

I don’t know if for this restriction level I need to reimplement some methods of the Ci_session class, or if it is enough to just set the CI parameters correctly?

If not, is there already a Codeigniter class or plugin that already has an activity like this implemented?

Example of how I am setting the parameters:

$config['sess_cookie_name']     = 'ci_session';
$config['sess_expiration']      = 420; 
$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']          = 420;
$config['sess_storage']                 = 'database';
$config['sess_database']                = 'default';
$config['sess_timeout']                 = 7200;
$config['sess_destroy_on_timeout']      = FALSE;
$config['sess_update_interval']         = 180;
$config['sess_gc_probability']          = 10;
$config['sess_http_only']               = FALSE;
$config['sess_secure']                  = FALSE;
$config['sess_forwarded_ip']            = FALSE; 

2 answers

2

I believe that Codeigniter does not have this, but this is very simple. Any request made in the application where any page contains session_start() at the beginning, the session will renew itself and start counting again, ie, will do the function you want.

If the user gets stuck on the page filling and rolling and etc, it can be dropped, exact? So also or at least another way to avoid this, is that you have an AJAX function, which calls some page whatever it contains session_start() to renew the session if it still has the page open. But this situation can vary a lot, as in a Lan House run out the time of the person, and in some browsers remain open depending on the Lan system.

So it’s good to think of some logic to manage your application.

  • because in the case of Codeigniter session_start() is not applicable. However I have already solved this problem in which I found the solution by simply reorganizing the configuration of the Codeigniter session.

2


I was able to solve the problem by simply rearranging the Codeigniter session configuration by setting in the file config.php of my application the parameters for the operation of the session.

Basically, I looked again at the Codeigniter documentation and removed some of the parameters that were left out from version 2.0 onwards.

I used the guidelines for each parameter of the IC session defined in the figure below:

inserir a descrição da imagem aqui

In my application, the parameters related to session configuration were as follows:

$config['sess_cookie_name']             = 'fwsibe';
$config['sess_expiration']              = 7200; 
$config['sess_expire_on_close']         = TRUE;
$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']          = 0;

I arrived at this solution thanks to the following post on the international stack overflow: Codeigniter Session Equal to Internet Banking

Browser other questions tagged

You are not signed in. Login or sign up in order to post.