2015-04-22 6 views
13

मैं codeigniterion_auth कॉन्फ़िगर , और MySQL के रूप में बैक-एंड, उपयोग कर रहा हूँ मेरे ऐप सुचारू रूप से संचालित लेकिन कुछ समय/नहीं बेतरतीब ढंग से जब मैं add/update कार्यों कॉल यह स्वचालित रूप से मुझे लॉग आउट। मैं पिछले 1 महीनों से इस पर काम कर रहा हूं लेकिन अब तक कोई समाधान नहीं मिला है? मैं ion_auth कॉन्फ़िगरेशन फ़ाइल में सेटिंग भी बदलता हूं।कोडनिर्देशक में ऑटो लॉगआउट को कैसे रोकें?

$config['user_expire'] = 0; 

कोई समस्या, इस समस्या का समाधान?
कृपया टिप्पणी करें, ताकि यदि आवश्यक हो तो मैं अधिक डेटा प्रदान कर सकता हूं।

नोट: मैंने this पर भी कोई भाग्य नहीं देखा है।

+1

के संभावित डुप्लिकेट [IonAuth - बेतरतीब ढंग से मुझे लॉग आउट किया जा रहा है] (http://stackoverflow.com/questions/19179243/ionauth-seems-to-be-randomly-logging-me-out) –

+0

यह कुछ और है, मेरा ऐप मुझे यादृच्छिक रूप से लॉग आउट नहीं करता है, लेकिन दिन में कम से कम 1 या 2 बार। –

उत्तर

8

आप शायद ajax अनुरोध प्रदर्शन कर रहे हैं, यह एक आम मुद्दा है ...

मैं तुम्हें सत्र डेटाबेस का उपयोग करने का सुझाव देते हैं और ajax कॉल कर सत्र को अद्यतन नहीं करने के लिए है कि ...

मेक आप सत्र वर्ग पर इस

class MY_Session extends CI_Session { 

public function sess_update() 
{ 
    $CI =& get_instance(); 

    if (! $CI->input->is_ajax_request()) 
    { 
     parent::sess_update(); 
    } 
} 
} 
+0

याहू मैं AJAX का उपयोग कर रहा हूं, लेकिन उन पृष्ठों के बारे में क्या है जहां मैंने अजाक्स का उपयोग नहीं किया था, जो मुझे –

1

प्रणाली में लाइन 346 की जगह/पुस्तकालयों/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()) 

आशा है कि यह आप के लिए काम करता है।

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(); 
    } 

} 

स्थान:

+0

से भी लॉग आउट कर रहा है। लेकिन कोई भाग्य एक ही समस्या नहीं है –

5

अपनी खुद की 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); 
    } 
+0

यदि मैं लिखता हूं तो 'if (! $ This-> सीआई-> इनपुट -> is_ajax_request()) वापसी माता-पिता :: sess_update(); 'session.php कन्स्ट्रक्टर में? क्या यह –

+1

काम करेगा हाँ यह काम करेगा। और यदि आपको कोई त्रुटि मिलती है तो कृपया मुझे बताएं। – Saty

+0

यह त्रुटि देता है 'किसी सदस्य फ़ंक्शन पर कॉल is_ajax_request() को c: \ xampp \ htdocs \ projects \ oinvoices \ system \ libraries \ Session.php पर लाइन पर 59' –

-1

यह सबसे अच्छा जवाब है।

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) 
         { 
      } 
        }); 
संबंधित मुद्दे