Welcome Guest, Not a member yet? Register   Sign In
RICK: Any solution yet, to get session expired on browser close?
#9

[eluser]nottRobin[/eluser]
Thanks for all your help above. I've implemented my own solution to this from the code above, and it's pretty simple.

The Simplest Solution!

Just download my attached MY_Session.php file and place it in
Code:
system/application/libraries
Then add this line to system/application/config/config.php:
Code:
['sess_persistant_cookie']   = FALSE;

That's it!

-----------------------

Or if you already have a MY_Session.php file, you can edit it accordingly. Here's the contents of MY_Session:
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Session extends CI_Session {
    private $sess_persistant_cookie = true;
    
    function __construct($params = array()) {
        // Run the parent's cookie
        parent::CI_Session($params);
        
        // Set the persistant cookie parameter:
        $this->sess_persistant_cookie = (isset($params['sess_persistant_cookie'])) ? $params['sess_persistant_cookie'] : $this->CI->config->item('sess_persistant_cookie');
    }
    
    /**
     * Write the session cookie
     *
     * @access    public
     * @return    void
     */
    /* Exact copy of the original function except where it says //=== new === */
    function _set_cookie($cookie_data = NULL) {
        if (is_null($cookie_data))
        {
            $cookie_data = $this->userdata;
        }

        // Serialize the userdata for the cookie
        $cookie_data = $this->_serialize($cookie_data);

        if ($this->sess_encrypt_cookie == TRUE)
        {
            $cookie_data = $this->CI->encrypt->encode($cookie_data);
        }
        else
        {
            // if encryption is not used, we provide an md5 hash to prevent userside tampering
            $cookie_data = $cookie_data.md5($cookie_data.$this->encryption_key);
        }
        
        //=== new ===
        // Session or persistant cookie...
        $expire = ($this->sess_persistant_cookie) ? $this->sess_expiration + time() : 0;
        
        // Set the cookie
        $ci =& get_instance();
        $ci->load->helper('cookie');
        set_cookie(array(
            'name'      => $this->sess_cookie_name,
            'value'     => $cookie_data,
            'expire'    => $expire,
            'domain'    => $this->cookie_domain,
            'path'      => $this->cookie_path
        ));
        //=== end new ===
    }
}


Messages In This Thread
RICK: Any solution yet, to get session expired on browser close? - by El Forum - 08-12-2010, 11:47 AM



Theme © iAndrew 2016 - Forum software by © MyBB