[英]Issue related to ajax requests causing session logout codeigniter
在当前的应用程序中,我向后端提出了许多ajax请求。
使用的Codeigniter版本是2.1.4。
因此,一段时间后会话注销,我认为由于会话更改和ajax请求仍使用过去的令牌发出请求。
使用codeigniiter版本2.2.1,我看到了一个修复程序:“修复了会话库中的一个错误,该错误在AJAX请求期间发生了会话ID的重新生成。” 由于我的到期时间为2小时,并且我有一个js页面应用程序且没有页面重新加载,因此在2.2.1版中,我需要发出ajax请求以每2小时在后台更改令牌,而没有其他ajax请求是发生。
谢谢。
在config.php中,检查并更新以下行的会话设置。
/*
|--------------------------------------------------------------------------
| Session Variables
|--------------------------------------------------------------------------
|
| 'sess_cookie_name' = the name you want for the cookie
| 'sess_expiration' = the number of SECONDS you want the session to last.
| by default sessions last 7200 seconds (two hours). Set to zero for no expiration.
| 'sess_expire_on_close' = Whether to cause the session to expire automatically
| when the browser window is closed
| 'sess_encrypt_cookie' = Whether to encrypt the cookie
| 'sess_use_database' = Whether to save the session data to a database
| 'sess_table_name' = The name of the session database table
| 'sess_match_ip' = Whether to match the user's IP address when reading the session data
| 'sess_match_useragent' = Whether to match the User Agent when reading the session data
| 'sess_time_to_update' = how many seconds between CI refreshing Session Information
|
*/
$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;
这是我面临相同问题的普遍问题。 为此,您必须创建扩展session
自定义会话类,然后自动加载自定义会话。
class MY_Session extends CI_Session {
public function sess_update()
{
$CI =& get_instance();
if ( ! $CI->input->is_ajax_request())
{
parent::sess_update();
}
}
}
有关更多详细信息,请检查此
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.