title: echo user in view from sessions code igniter
body: <p>I am new in codeigniter. I have implemented a simple login system. I want to print out a username on my view page which is stored in sessions.
   here is my controller</p>
  
  <pre><code>class LoginController extends CI_Controller {
  
  function index(){           
          $new['main_content'] = 'loginView';
          $this-&gt;load-&gt;view('loginTemplate/template', $new); 
  
      }   
  
      function verifyUser(){          
          //getting parameters from view 
          $data = array(
                  'username' =&gt; $this-&gt;input-&gt;post('username'),
                  'password' =&gt; $this-&gt;input-&gt;post('password')
          );          
  
          $this-&gt;load-&gt;model('loginModel'); 
          $query = $this-&gt;loginModel-&gt;validate($data);   
  
                if ($query){             
              //if the user c validated
              //data variable is created becx we want to put username in session
                  $data = array(
                      'username' =&gt; $this-&gt;input-&gt;post('username'),
                       'is_logged_in' =&gt; true 
                  );
  
                 $this-&gt;session-&gt;set_userdata($data);
               redirect('sessionController/dashboard_area');
          }
          else
           {
              $this-&gt;index();
          }
      }
      function logout()
      {
          $this-&gt;session-&gt;sess_destroy();
          $this-&gt;index();
      }
      }
      ?&gt;
  </code></pre>
  
  <p>sessionController</p>
  
  <pre><code>&lt;?php
  
            class SessionController extends CI_Controller {
  
  function __construct()
  {
      parent::__construct();
      $this-&gt;is_logged_in();
  
  }
  
  
  
  function dashboard_area(){
  
  
      $data['main_content'] = 'dashboardView';
      $this-&gt;load-&gt;view('dashboardTemplate/template', $data);
  
  }
  
  function is_logged_in()
  {
      $is_logged_in = $this-&gt;session-&gt;userdata('is_logged_in');
      if(!isset($is_logged_in) || $is_logged_in != true)
      {
          echo 'You don\'t have permission to access this page.';
          die();
          //$this-&gt;load-&gt;view('login_form');
      }else {
  
      return true;
  
      }
  }
  
  
         }
    ?&gt;
  </code></pre>
  
  <p>how can i stored a username in sessions and then print out in a page ... i dont want to save username in every controller</p>
  
  <p>if any one have a better suggestions to implement then please share it to me .. </p>