अपनी खुद की MY_Session.php
पुस्तकालय को अधिलेखित कर दिया है कि यह है कि केवल अद्यतन विधि जब नहीं एक AJAX अनुरोध निष्पादित एक साथ sess_update
विधि के साथ एक सत्र पुस्तकालय बनाएं फ़ाइल:
/एप्लिकेशन/पुस्तकालय/एमवाई_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's 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);
}
के संभावित डुप्लिकेट [IonAuth - बेतरतीब ढंग से मुझे लॉग आउट किया जा रहा है] (http://stackoverflow.com/questions/19179243/ionauth-seems-to-be-randomly-logging-me-out) –
यह कुछ और है, मेरा ऐप मुझे यादृच्छिक रूप से लॉग आउट नहीं करता है, लेकिन दिन में कम से कम 1 या 2 बार। –