title: codeigniter how pass login session in all controller
body: <p>how to pass login session user data  in my all controller pages:
  i tried lot of codes but note working anything. please any one can help me.
  also load session library session .it get error</p>
  
  <pre><code>Severity: Notice: Undefined variable: session_data
  
  Filename: controllers/Banner.php
  
  Line Number: 11
  
  Backtrace:
  
  File: C:\xampp\htdocs\aapkavyavahar\admin\application\controllers\Banner.php
  Line: 11
  Function: _error_handler
  
  File: C:\xampp\htdocs\aapkavyavahar\admin\index.php
  Line: 315
  Function: require_once
  </code></pre>
  
  <p>My login contoller:</p>
  
  <pre><code>    function login_validation()  
    {  
  
         $this-&gt;load-&gt;library('form_validation');  
         $this-&gt;form_validation-&gt;set_rules('username', 'Username', 'required');  
         $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'required');  
         if($this-&gt;form_validation-&gt;run())  
         {  
              //true  
              $username = $this-&gt;input-&gt;post('username');  
              $password = $this-&gt;input-&gt;post('password');  
              //model function  
              $this-&gt;load-&gt;model('main_model');  
              if($this-&gt;main_model-&gt;can_login($username, $password))  
              {  
                   $session_data = array(  
                        'username'     =&gt;     $username  
                   );  
                   $this-&gt;session-&gt;set_userdata($session_data);  
                   redirect('login/enter');  
              }  
              else  
              {  
                   $this-&gt;session-&gt;set_flashdata('error', 'Invalid Username or Password');  
                   redirect('login/index');  
              }  
         }  
         else  
         {  
              //false  
              $this-&gt;index();  
         }  
    }  
  public function enter(){  
         if($this-&gt;session-&gt;userdata('username') != '')  
         {  
              $this-&gt;load-&gt;view('includes/dashlink');
              $this-&gt;load-&gt;view('includes/dashheader');
              $this-&gt;load-&gt;view('index');
              $this-&gt;load-&gt;view('includes/dashfooter');
  
  
         }  
         else  
         {  
              redirect(base_url() . 'login/index');  
         }  
    }  
  public function logout() {
  
  $this-&gt;session-&gt;sess_destroy();
  $data['message_display'] = 'Successfully Logout';
  $this-&gt;load-&gt;view('login', $data);
  
      } 
  </code></pre>
  
  <p>Other controller :</p>
  
  <pre><code>   function __construct() {
              parent::__construct();
  $this-&gt;load-&gt;library('session');
      if(!$this-&gt;session-&gt;userdata(' $session_data')){
      redirect(login);
      }
          }
  </code></pre>