Как предотвратить автоматический выход из системы в кодеринговом?
Я использую codeigniter
с ion_auth
настроен, а MySQL - как серверный,
мое приложение работает плавно, но когда-то/не случайным образом, когда я вызываю add/update
функции, он автоматически выводит меня из системы.
Я работаю над этим в течение последних 1 месяца, но не нашел решения до сих пор?
Я также изменяю настройку в файле конфигурации ion_auth
.
$config['user_expire'] = 0;
любая идея, решение этой проблемы?
пожалуйста, прокомментируйте, чтобы я мог предоставить больше данных, если это необходимо.
Примечание: я также проверил этот, но не повезло.
Ответы
Ответ 1
Вероятно, вы выполняете запросы ajax, это обычная проблема...
Я бы предложил вам использовать базу данных сеанса и сделать аякс-вызовы не обновлять сеанс...
Сделайте это для вас классом сеанса
class MY_Session extends CI_Session {
public function sess_update()
{
$CI =& get_instance();
if ( ! $CI->input->is_ajax_request())
{
parent::sess_update();
}
}
}
Ответ 2
Создайте библиотеку сеансов со своей собственной библиотекой MY_Session.php
, которая перезаписала метод sess_update
тем, который выполнил только метод обновления, если не был запрошен AJAX:
MY_Session.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once BASEPATH . '/libraries/Session.php';
class MY_Session extends CI_Session
{
function __construct()
{
parent::__construct();
$this->CI->session = $this;
}
function sess_update()
{
// Do NOT update an existing session on AJAX calls.
if (!$this->CI->input->is_ajax_request())
return parent::sess_update();
}
}
Расположение файла:
/application/libraries/MY_Session.php */
Вы можете либо автозагрузить эту библиотеку из config/autoload.php:
$autoload['libraries'] = array( 'MY_Session');
Или вы можете загрузить его позже:
$this->load->library('MY_Session');
Что это sess_update(); делает?
В вашем system/libraries/Session.php
есть function sess_update()
, который автоматически обновляет ваше последнее действие. Эта функция обновляет сеанс каждые пять минут по умолчанию.
public function sess_update()
{
// We only update the session every five minutes by default
if (($this->userdata['last_activity'] + $this->sess_time_to_update) >= $this->now)
{
return;
}
// _set_cookie() will handle this for us if we aren't using database sessions
// by pushing all userdata to the cookie.
$cookie_data = NULL;
/* Changing the session ID during an AJAX call causes problems,
* so we'll only update our last_activity
*/
if ($this->CI->input->is_ajax_request())
{
$this->userdata['last_activity'] = $this->now;
// Update the session ID and last_activity field in the DB if needed
if ($this->sess_use_database === TRUE)
{
// set cookie explicitly to only have our session data
$cookie_data = array();
foreach (array('session_id','ip_address','user_agent','last_activity') as $val)
{
$cookie_data[$val] = $this->userdata[$val];
}
$this->CI->db->query($this->CI->db->update_string($this->sess_table_name,
array('last_activity' => $this->userdata['last_activity']),
array('session_id' => $this->userdata['session_id'])));
}
return $this->_set_cookie($cookie_data);
}
// Save the old session id so we know which record to
// update in the database if we need it
$old_sessid = $this->userdata['session_id'];
$new_sessid = '';
do
{
$new_sessid .= mt_rand(0, mt_getrandmax());
}
while (strlen($new_sessid) < 32);
// To make the session ID even more secure we'll combine it with the user IP
$new_sessid .= $this->CI->input->ip_address();
// Turn it into a hash and update the session data array
$this->userdata['session_id'] = $new_sessid = md5(uniqid($new_sessid, TRUE));
$this->userdata['last_activity'] = $this->now;
// Update the session ID and last_activity field in the DB if needed
if ($this->sess_use_database === TRUE)
{
// set cookie explicitly to only have our session data
$cookie_data = array();
foreach (array('session_id','ip_address','user_agent','last_activity') as $val)
{
$cookie_data[$val] = $this->userdata[$val];
}
$this->CI->db->query($this->CI->db->update_string($this->sess_table_name, array('last_activity' => $this->now, 'session_id' => $new_sessid), array('session_id' => $old_sessid)));
}
// Write the cookie
$this->_set_cookie($cookie_data);
}
Ответ 3
Заменить строку 346 в системе /library/Session.php(функция sess_update())
if (($this->userdata['last_activity'] + $this->sess_time_to_update) >= $this->now)
С
if (($this->userdata['last_activity'] + $this->sess_time_to_update) >= $this->now || $this->CI->input->is_ajax_request())
надеюсь, что это сработает для вас.
Ответ 4
это лучший ответ.
codeignter controller
function fetchSendToProduction($sku,$old_fab_id)
{
if($this->input->is_ajax_request() > 0)
{
$result = $this->ifmodel->fetchSendToProduction($sku,$old_fab_id);
echo json_encode($result);
}
}
codeignter view ajax call
$.ajax({
type: "POST",
url: "<?php echo base_url(); ?>index.php/inputFactor/fetchSendToProduction/" + sku+'/'+old_fab_id ,
cache: false,
processData: false,
success: function(data)
{
}
});