The codeigniter session often ends

I am using codeigniter for my application

that my problem in the session ends even if the user is active on the site.

These are the session settings. I am using a DB session

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

any solution for this.

help me i need to fix it

here is the codeigniter link

+6
source share
5 answers

I am having problems with CI sessions that were random. Do you have AJAX or dynamic resources loading a session library? If so, imagine this scenario:

I send an ajax request (which passes in my CI session id with a cookie) and it returns the results, BUT I also send another request (loading a dynamic image, another AJAX request, etc.) that immediately follows the first request. The first request can trigger a 300-second time-to-refresh event and send a new cookie, but the extra request sends the old session identifier, right?

So CodeIgniter says, β€œHey, you can't do this,” and creates a new session, invalidating both cookies, which my browser now does not know what to do.

Here's a link to a forum that I posted some time ago, in more detail: http://codeigniter.com/forums/viewthread/172415/

+13
source

As mentioned in the first answer, there is a race condition in the session library that has since softened somewhat in recent versions of CodeIgniter, including the "develop" branch. This implements isAjax validation on session rotation, but it doesn’t actually fix the underlying problem.

+3
source

Are you sure the session is destroyed? I think that it just does not update as intended, and creates a new request for each page. (general problem with installing Codeigniter)

here are my suggestions:

double check the Application / Config / config.php file to make sure that part of the session domain looks like this if you host the site in the main directory:

 $config['cookie_prefix'] = ""; $config['cookie_domain'] = "yourdomain.com"; $config['cookie_path'] = "var/sessions/"; $config['cookie_secure'] = FALSE; 

and the like, if you host the site in a subdirectory:

 $config['cookie_prefix'] = ""; $config['cookie_domain'] = "yourdomain.com"; $config['cookie_path'] = "siteSubDirectory/var/sessions/"; $config['cookie_secure'] = FALSE; 

and make sure that 2 directories are writable by setting their permissions to 755 or so, and I highly recommend that you enable a database session that is more secure and helps you find the real problem by checking the session table. good luck :)

+2
source

I will add a workaround for this problem. if an ajax call is made, do not update the session, expand the session class by adding this file to the libraries folder:

  class MY_Session extends CI_Session { // -------------------------------------------------------------------- /** * sess_update() * * @access public * @return void */ public function sess_update() { $CI =& get_instance(); if ( ! $CI->input->is_ajax_request()) { parent::sess_update(); } } } 
+2
source

Just change the encoding of the ci_sessions table in MyISAM: ALTER TABLE ci_sessions ENGINE = MyISAM;

+1
source

Source: https://habr.com/ru/post/893760/


All Articles