• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
session data not working at all

#1
im having a really weird issue with CodeIgniter 3, the main issue is that logged_in is not being passed, its always empty and when it gets to dashboard.php its always empty and it is redirected to the login page again, doesnt matter if the user/pass is correct, logged_in is always false because it is never set

this is the authenticate class:

PHP Code:
<?php 
class Authenticate extends MY_Controller{
    public function 
login(){
        
$this->form_validation->set_rules('username','Username','trim|required|min_length[4]|xss_clean');
        
$this->form_validation->set_rules('password','Password','trim|required|min_length[4]|xss_clean');
        if (
$this->form_validation->run() == FALSE) {
            
//Load View
            // echo CI_VERSION ;
            
$this->load->view('admin/layouts/login');
        } else {
            
//Get From Post
            
$username $this->input->post('username');
            
$password $this->input->post('password');
            
            
//Validate Username & Password
            
$user_id $this->Authenticate_model->login_user($username$password);
            
            if(
$user_id){//
                
$user_data = array(
                        
'user_id'   => $user_id,
                        
'username'  => $username,
                        
'logged_in' => true
                
);
                
//Set session userdata
 
                               // This is where its not working, logged_in  is not passed at all,
 
                               // so 
                
$this->session->set_userdata($user_data);
                
                
//Set message
 
                              
                $this
->session->set_flashdata('pass_login''You are now logged in');
                
redirect('admin/dashboard');
            }

            else {
                
$login_data $this->session->userdata('logged_in' ) ;            
                
$this->session->set_flashdata('fail_login''Wrong Username or Password, Try again') ;
                
redirect('admin/login');
            }


        }
    }

== this is the dashboard.php ===
PHP Code:
<?php 
class Dashboard extends MY_Controller{
    public function 
__construct(){
        
parent::__construct();
        
        
//Access Control
 
               // logged_in is always empty and is never passed so its always redirected to the 
 
               // admin login page, doesnt matter if the user/pass is correct
        
if(!$this->session->userdata('logged_in')){
            
redirect('admin/login');
        }
    }

    public function 
index(){
        
//Get Articles
        
$data['articles'] = $this->Article_model->get_articles('id','DESC',10);
        
        
//Get Categories
        
$data['categories'] = $this->Article_model->get_categories('id','DESC',5);
        
        
//Get Users
        
$data['users'] = $this->User_model->get_users('id','DESC',5);
        
        
//View
        
$data['main_content'] = 'admin/dashboard/index';
        
$this->load->view('admin/layouts/main',$data);
    }


=== in autoload.php ===
PHP Code:
$autoload['libraries'] = array('database''session''form_validation'); 

the problem is in authenticate where its not passing the value for logged_in , this code works in Codeigniter 2, but not for version 3


Attached Files
.php   authenticate.php (Size: 1.59 KB / Downloads: 21)
.php   dashboard.php (Size: 645 bytes / Downloads: 20)
Reply

#2
Did you follow step 6 in the documentation for upgrading from 2.x to 3.0?
https://www.codeigniter.com/user_guide/i...e_300.html

CI 3.x is quite different from CI 2.x when it comes to sessions.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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