Welcome Guest, Not a member yet? Register   Sign In
AJAX and CI Session (v1.7) w/DB
#21

[eluser]mcjimbob[/eluser]
that's even better - thanks!
#22

[eluser]wallysson[/eluser]
well, i haven't the second page, so i reconstruct my method, before i change my class, i sent for the model severy ajax request wich haves diferent ids, now i send one ajax request with an array, and in the model i make an loop wich retrieves each id.

Well, i spent 2 hours or more fixing my methods, but it could be an way...
#23

[eluser]wallysson[/eluser]
For anyone who get the same problem, and maybe can't just don't update ajax calls, just follow this link and everything will work, you will lose a litlle of security, but for me it will be ok.

The security problem it's because your session_id will never get updated... better than don't update nothing... Was my problem because i'm using Extjs framework at frontend, and in this system you don't have any refresh on the browser, everything are made with ajax calls...

Luck 4 everyone, and God bless you!
#24

[eluser]wallysson[/eluser]
I did fill changes on the else state:
Code:
else {
    $new_sessid = $old_sessid;
    $this->userdata['session_id'] = $old_sessid;
}
#25

[eluser]Kobus M[/eluser]
Hi guys,

I have tried EVERY solution mentioned so far. I have spent days on this sofar. I keep getting random session expiration when having Ajax requests. Here is some of what I tried.

1. Replaced Session.php: http://stackoverflow.com/questions/15829...ng-on-webp
2. Tried all variants of this fix that I could find: https://degreesofzero.com/article/fixing...niter.html
3. Everything in this thread: http://ellislab.com/forums/viewthread/102456
4. I tried this: http://www.hiretheworld.com/blog/tech-bl...conditions
5. This: https://github.com/EllisLab/CodeIgniter/pull/1283
6. And this: https://github.com/EllisLab/CodeIgniter/pull/1900
7. Also: http://upshots.org/codeigniter/codeignit...on-bug-fix

I am really at a loss - it is making me grey before my age... :-(

Anybody else with something I can try?

Kind regards,

Kobus
#26

[eluser]InsiteFX[/eluser]
You can try this is works for me.
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* ------------------------------------------------------------------------
* Created by Php Designer 8.1.2.
* 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 sessions
* @author  Raymond L King Sr.
* @link  http://example.com
* ------------------------------------------------------------------------
* To change this template use File | Settings | File Templates.
* ------------------------------------------------------------------------
*/

/**
* ------------------------------------------------------------------------
* CI Session Class Extension for AJAX 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();
  }
    }

} // End of class MY_Session.

/* ------------------------------------------------------------------------
* Filename: MY_Session.php
* Location: ./application/libraries/MY_Session.php
* ------------------------------------------------------------------------
*/
#27

[eluser]Karman de Lange[/eluser]
The only semi reliable method that works for me is as per insiteFX but also adding:
in config.php

Code:
$config['sess_time_to_update'] = $config['sess_expiration'];
##Make sure coockies are encrypted
$config['sess_encrypt_cookie'] = TRUE;

And if still issues set async to false on all ajax or simply set global to false.
Code:
$.ajaxSetup({
                async: false
            });

I now only get kicked out every few days.. not every 5 minutes

#28

[eluser]jonez[/eluser]
If it's an option upgrade to CI3 and using the native session driver. It doesn't have this problem with AJAX calls.

Like you I pulled my hair out for a while on this one. Almost swapped away from CI because of it. Every fix I found lowered security in other respects. Then a wild CI3 appeared and it was super effective.

Code:
$.ajaxSetup({
     async: false
});
You do NOT want to do this. Synchronous AJAX calls should be avoided at all costs. Setting it globally is a very bad idea. While a synchronous call is running it locks your browser and users cannot interact with the page.
#29

[eluser]Karman de Lange[/eluser]
[quote author="jonez" date="1393011316"]If it's an option upgrade to CI3 and using the native session driver. It doesn't have this problem with AJAX calls.

Like you I pulled my hair out for a while on this one. Almost swapped away from CI because of it. Every fix I found lowered security in other respects. Then a wild CI3 appeared and it was super effective.

Code:
$.ajaxSetup({
     async: false
});
You do NOT want to do this. Synchronous AJAX calls should be avoided at all costs. Setting it globally is a very bad idea. While a synchronous call is running it locks your browser and users cannot interact with the page.[/quote]

Yup, bad idea... but better than users shouting at you every 5 minutes cause they have to login again ;-)

Will checkout CI 3 on next project
#30

[eluser]jonez[/eluser]
[quote author="Karman de Lange" date="1393175179"]Yup, bad idea... but better than users shouting at you every 5 minutes cause they have to login again ;-)[/quote]
If a timeout occurs the browser will lock for a solid 5+ seconds. It may not seem that bad when the server responds quickly but any time it doesn't you will see why this isn't a proper solution.




Theme © iAndrew 2016 - Forum software by © MyBB