CodeIgniter Forums
Session Disappear - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 2.x (https://forum.codeigniter.com/forumdisplay.php?fid=18)
+--- Thread: Session Disappear (/showthread.php?tid=631)



Session Disappear - PolatAlemdar - 12-29-2014

I set the session variable but it disappears. $data in setsession function is a result of a query (row_array).

I have seen this site linked below and I am using SlimBrowser (Chrome copy) in Windows Localhost. Is there a change in this situation stated in the page? I started CI a few days ago now I am planning to never use it again??? I have been trying to understand how a session disappears and gave hours on that... Angry

http://billpatrianakos.me/blog/2013/03/22/codeigniter-session-problems/

setting function:
PHP Code:
public function setsession($data){
        
$this->session->set_userdata("user_data",$data);
        
$this->session->set_userdata('logged_in',true);
        
print_r($this->session->all_userdata());
        
//$data=$this->session->all_userdata();
    


Checking function:
PHP Code:
public function isloggedin()
    {
        
$data=$this->session->userdata("logged_in");
        if(
$data==false){
            return 
false;
        }
        return 
true;
    } 

I would be grateful if someone can help.


RE: Session Disappear - Avenirer - 12-29-2014

First of all you should make sure you've loaded the session library/driver.

So, if you didn't autoload it, you can load it inside the two functions.

Now... if you have CI 2.x... you can load it with 
PHP Code:
$this->load->library('session'); 

If you have CI 3.dev you can load it with
PHP Code:
$this->load->driver('session'); 

Worth mentioning...
if setsession() method is called from the controller and not from browser you should make the function (method) private...


RE: Session Disappear - PolatAlemdar - 12-29-2014

set_session method is in model. and I have already included session in model and controller.

Still session variable disappears.


RE: Session Disappear - PolatAlemdar - 01-07-2015

OK. I switched to using PHP's session variable.