Welcome Guest, Not a member yet? Register   Sign In
Session problem
#11

[eluser]Mackstar[/eluser]
Yes I completely agree with you, code igniters strength is that it is easy to extend, with only the base I don't think it would be strong enough for most of our needs.

I have been extending most other parts of the framework like models, controllers, hooks etc but hadn't yet needed to play with sessions... But maybe your session class maybe a good solution.
#12

[eluser]rbncha[/eluser]
Hi,

It didn't help me. can you tell me why ?
#13

[eluser]Mackstar[/eluser]
I order to know how the sessions work, you need to know about cookies and how they are set. A CI session sets a cookie which you set its length in the config files. There are 2 ways to set cookies, one is to set a time at which you want it to expire(CI) uses this method by default. Hence changing the amount of time in the config files changes this value.

The other is when you don't specify a time, this type will expire when the browsers session expires (usually when shut down).

So in order to make the session expire when you close the browser you have to make CI save its cookies in the as in the 2nd method.
#14

[eluser]Zeeshan Rasool[/eluser]
May be im wrong but CI has some problem with session handling. I also have problems some times. Your problem is very important to you,

If your sessions are using a cookie to propagate the session id, then the session.cookie_lifetime setting should be set to 0 (zero) to cause the session to expire when the browser is closed.
otherwise if you are using session handling thru table then..

you need a function that checks each time when you are going to new controller's function each time and expires the session if time is exceeded that you have given. So, put a session expiration check before each function in controller that may check and delete the session from table if its exceeds the limit you set.
Code:
$sSQL        = 'DELETE FROM ci_sessions WHERE last_activity<='.strtotime("-3000 minutes").'';
$sResult    = $this->db->query($sSQL);
$res        = FALSE;
$sess        = $this->session->userdata('session_id');
If time is not over then check the session record in table and return true to give permission for accessing functions or site page.
Code:
$query = $this->db->getwhere('ci_sessions', array('session_id' => $sess));

foreach ($query->result() as $row)
{
    if(@$row->logged_in!='' && @$row->logged_in!=0)
    {
      $res=1;
    }
    else
    {
      $res=0;
    }
}
return $res;

Hope it will help
#15

[eluser]Unknown[/eluser]
application/libraries/MY_Session.php
Code:
&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Session extends CI_Session {

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

        if ($this->sess_expiration == -1)
        {
            $expiration = 0;
        }
        else
        {
            $expiration = $this->sess_expiration + time();
        }

        // Set the cookie
        setcookie(
                    $this->sess_cookie_name,
                    $cookie_data,
                    $expiration,
                    $this->cookie_path,
                    $this->cookie_domain,
                    0
                );
    }

}
?&gt;

How to
Code:
function writess()
    {
        $this->config->set_item('sess_expiration', -1);
        $this->load->library('session');
        $data = array(
            'username' => 'mrtee',
            'email' => '[email protected]',
            'logged_in' => TRUE
        );
        $this->session->set_userdata($data);
    }
#16

[eluser]Unknown[/eluser]
Before to close mozial firefox you have recevived a massege from save & quit or quit you have to select save & quit option.




Theme © iAndrew 2016 - Forum software by © MyBB