Welcome Guest, Not a member yet? Register   Sign In
Need help with sessions library
#1

[eluser]condoace[/eluser]
I am trying to redirect a user to a login page if no sessions are detected, but my code below is not working - it just keeps redirecting to index() within the class, not checking the is_logged_in() method... any ideas??

Code:
class Cars extends CI_Controller {
    
        function __construct()
        {
            
            parent::__construct();
            
            $this->is_logged_in();
        
        }
        
        function index()
        {
        
            $this->load->view('cars/addcar_view');
        
        }
        
        
        function is_logged_in()
        {
                    
            $check = $this->session->userdata('logged_in');
            
            if(!isset($check))
                {
                
                    redirect('login/index');
                
                }        
        
        }

    }
#2

[eluser]WanWizard[/eluser]
$this->session->userdata is a method that always returns a value. So isset() always returns TRUE.
#3

[eluser]condoace[/eluser]
ah ok thanks...used !empty instead




Theme © iAndrew 2016 - Forum software by © MyBB