• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
simple problem with session (login)

#1
Good day.
I broke my brain with this problem.

This is code in controller Login

PHP Code:
    private $logged_in;
    private 
$login;

    public function 
__construct()
    {
        
parent::__construct();
        
$this->load->model('login_model');

        if(
$this->session->userdata('logged_in')){
            
$this->logged_in true;
            
$this->login $this->session->userdata('login');
        }
        else{
            
$this->logged_in false;
            
$this->login '';
        }
    }

    public function 
index()
    {
        
$data_r=array();

        
$CI = & get_instance ();
        
$CI->load->view('site_head',$data_r);
        
$CI->load->view('site_reg',array('logged_in'=>$this->logged_in,'login'=>$this->login));
        
$CI->load->view('site_header');

        if(
$this->logged_in){
            
redirect('/''location');
        }
        else{
            
$CI->load->view('login_site',array('logged_in'=>$this->logged_in));
        }
        
$CI->load->view('site_footer');
    } 
After autorization if i put login button, i see that $this->logged_in is TRUE. ANd redirect to main page.
But this code main controller
PHP Code:
    private $logged_in;
    private 
$login;

    public function 
__construct()
    {
        
parent::__construct();

        
//$this->load->library('session');
        
if($this->session->userdata('logged_in')){
            
$this->logged_in true;
        }
        else{
            
$this->logged_in false;
        }
    } 

And in function index() $this->logged_in is FALSE

Why? Thanks for help
Reply

#2
What is $this->session->userdata('logged_in') value? Have your dump $_SESSION? You can set session userdata by using $this->session->set_userdata('some_name', 'some_value'). The userdata() method returns NULL if the item you are trying to access does not exist.
Keep calm.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.