Welcome Guest, Not a member yet? Register   Sign In
Session requires login after login
#1

I have a website that has a  login requirement to access functions on a certain controller. The login portion works fine and I can access one of the functions in the controller. But if I try to access any other function the log in screen pops up and requires me to log in again, however I can never get to the page I want it will just ask me to log in again. Below is a php code. The main controller handles all of the login functionality. The ATIS controller checks to see if the user is logged in. 

ATIS Controller (The secure section)

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Atis extends CI_Controller 
{
        public 
$status
 
       public $roles;
public function 
__construct()
    {
        
parent::__construct();
    
$this->load->model('User_model''user_model'TRUE);
    
$this->status $this->config->item('status'); 
 
   $this->roles $this->config->item('roles');    
 
   $this->is_logged_in();
    }

public function 
index(){   
    $this
->load->view("atis/inc/header");
    
$this->load->view("atis/dashboard");
    
$this->load->view("atis/inc/footer");
    }
public function 
is_logged_in() 

$is_logged_in $this->session->userdata('is_logged_in'); 
if(!isset(
$is_logged_in) || $is_logged_in !=TRUE) 

redirect('main/login'); // If I take this out I can access the other functions previously asking for me to log in again but takes away the necessity to login to view the other functions. 
exit(); 




Main Controller (Where the login function happens)

PHP Code:
public function login()
 
       {
 
           $this->form_validation->set_rules('email''Email''required|valid_email');    
            $this
->form_validation->set_rules('password''Password''required'); 
 
           
            if
($this->form_validation->run() == FALSE) {
 
               $this->load->view('inc/site_header');
 
               $this->load->view("site_nav"); 
 
               $this->load->view('login');
 
               $this->load->view('inc/site_footer');
 
           }else{
 
               
                $post 
$this->input->post();  
                $clean 
$this->security->xss_clean($post);
 
               $userInfo $this->user_model->checkLogin($clean);
 
               
                if
(!$userInfo)
 
               {
 
                   $this->session->set_flashdata('flash_message''The login was unsucessful');
 
                   redirect(site_url().'main/login');
 
               }
 
               else
                
{
 
                   foreach($userInfo as $key=>$val)
 
                   {
 
                       $this->session->set_userdata($key$val);
 
                   }
 
                   $this->session->set_userdata('is_logged_in'TRUE);
 
                   redirect(site_url().'atis/');
 
               }
 
          
 
       
Reply
#2

maybe you forgot to load the session library in the controller which the login process happen.
Just a random guy from Internet
Reply
#3

The session library is autoloaded
Reply




Theme © iAndrew 2016 - Forum software by © MyBB