Welcome Guest, Not a member yet? Register   Sign In
Keeping CI Session Alive
#1

[eluser]nagata[/eluser]
I have small problem, I need to keep my websites user session alive...
I tried to use Ajax,
I created a small function in controller, routed it right way,
Wrote jQuery Ajax code to request that uri each minute (small for testing...)
But it dosent seem to update other info of user...
the prefab view
Code:
<?php
$ident=$this->session->userdata('id');
if ($ident) {
$this->users_model->i_am_on($ident);}
?>
the renew function in controller
Code:
function renew()
{
$this->load->view('templates/prefab');
}
the jQuery code in the header template that calls the renew function
Code:
[removed]  
        function show()  
        {  
            $.ajax({  
                url: "/index.php/member/renew",  
                cache: false,  
                success: function(html){}
            });    
        }  
  
  $(document).ready(function() {
         show();  
            setInterval('show()',1000*30);   //Updates each 30 seconds...
  });
  
  
  [removed]

So guys, any help on making it work, or any other aproac to this problem?
I need this...
Also If possible with code Smile
#2

[eluser]nagata[/eluser]
-Bump-
I need this, any help is appriciated Smile
#3

[eluser]CroNiX[/eluser]
Because you're not doing anything with the returned data in your ajax success event. You're returning the html for the page, but not doing anything with it. You need to replace the current pages html with what you are returning.

However, why don't you just increase the sess_expiration time if you want the session to last longer?
#4

[eluser]nagata[/eluser]
there is simply nothing to return so i am not changing anything, if it would be hard for you mighty CroNiX, please write me a code of how to keep this session alive Smile
#5

[eluser]LeMec[/eluser]
Hello,

sess_expiration time is one thing, but it does not help all the time...
The only way the problem was solved for me was to do this:

Code:
$config['sess_time_to_update']  = PHP_INT_MAX;

Essentially telling CI to never change the encryption.
I read a while back that the problem has to do with Ajax...

On an Ajax request, the database session info might be re-encrypted, but the web browser might not causing the log out...

We need to tell CI not to update if it is an Ajax request but I don't know how.

Alain
#6

[eluser]InsiteFX[/eluser]
./application/libraries/MY_Session.php
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* ------------------------------------------------------------------------
* Created by phpDesigner 8.
* Date : 5/6/2012
* Time : 11:19:06 PM
* The Learn CodeIgniter Development Team.
* ------------------------------------------------------------------------
*
* Class MY_Session
*
* @package  Package  CodeIgniter
* @subpackage Subpackage session
* @category category session
* @author  Raymond L King Sr.
* @link  http://example.com
* ------------------------------------------------------------------------
* To change this template use File | Settings | File Templates.
* ------------------------------------------------------------------------
*/

/**
* ------------------------------------------------------------------------
* CI Session Class Extension for AJAX and Xajax method calls.
* ------------------------------------------------------------------------
*
* ====- Save as ./application/libraries/MY_Session.php -====
*/

class MY_Session extends CI_Session {

// --------------------------------------------------------------------

/**
  * sess_update()
  *
     * Do not update an existing session on ajax or xajax calls
     *
     * @access    public
     * @return    void
     */
    public function sess_update()
{
  $_ci = get_instance();

  if ( ! $_ci->input->is_ajax_request())
  {
   parent::sess_update();
  }
    }

// --------------------------------------------------------------------

/**
  * sess_destroy()
  *
     * Clear's out the user_data array on sess::destroy.
     *
     * @access    public
     * @return    void
     */
public function sess_destroy()
{
  $this->userdata = array();

  parent::sess_destroy();
}

} // End of Class.

/* ------------------------------------------------------------------------
* End of file MY_Session.php
* Location: ./application/libraries/MY_Session.php
* ------------------------------------------------------------------------
*/
#7

[eluser]nagata[/eluser]
Okay Guys thanks for all reply's
But I have found a solution of my own.
Again thank you everyone.




Theme © iAndrew 2016 - Forum software by © MyBB