Welcome Guest, Not a member yet? Register   Sign In
CI, Sessions, Ajax and expiration
#4

[eluser]Codepeak[/eluser]
Good idea! I'll check the cookie being sent by the AJAX request.

Here's a modification to the Session library to not to do any write or update actions if the controller is ajax. Not fully optimized or nicely done, but does what it should during my debugging. I've also added log_message to almost every line of the session library so I can see what and where it goes wrong Smile

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class My_Session extends CI_Session {

    /**
     * Check if it's a ajax request
     *
     * If the current call is a ajax request, determinated
     * by POST-variable is_ajax, then the session should
     * not be updated.
     *
     * Every AJAX request should POST the variable is_ajax
     * to the controller to have this work.
     *
     */
    
    var $myCI = FALSE;

    function load_my_CI()
    {
        if ( $this->myCI === FALSE )
        {
            $this->myCI =& get_instance();
        }
        return;
    }
    
    function sess_update()
    {
        $this->load_my_CI();
        if ( $this->myCI->uri->segment(1) !== 'ajax' )
        {
            parent::sess_update();
        }
    }
    
    function sess_write()
    {
        $this->load_my_CI();
        if ( $this->myCI->uri->segment(1) !== 'ajax' )
        {
            parent::sess_write();
        }
    }
}


Messages In This Thread
CI, Sessions, Ajax and expiration - by El Forum - 12-23-2010, 08:37 AM
CI, Sessions, Ajax and expiration - by El Forum - 12-23-2010, 08:40 AM
CI, Sessions, Ajax and expiration - by El Forum - 12-23-2010, 09:19 AM
CI, Sessions, Ajax and expiration - by El Forum - 12-23-2010, 09:52 AM
CI, Sessions, Ajax and expiration - by El Forum - 12-23-2010, 10:09 AM
CI, Sessions, Ajax and expiration - by El Forum - 12-23-2010, 11:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB