title: How to show user name after login in codeigniter
body: <p>How to show user name after login in <strong>codeigniter</strong>?</p>
  
  <pre><code>&lt;?php
  
  class Users_model extends CI_Model {
  
      function validate($user_name, $password)
      {
          $this-&gt;db-&gt;where('user_name', $user_name);
          $this-&gt;db-&gt;where('pass_word', $password);
          $query = $this-&gt;db-&gt;get('membership');      
          if($query-&gt;num_rows &gt;= 1)
          {
              return true;
          }       
      }
  
      function get_db_session_data()
      {
          $query = $this-&gt;db-&gt;select('user_data')-&gt;get('ci_sessions');
          $user = array(); /* array to store the user data we fetch */
          foreach ($query-&gt;result() as $row)
          {
              $udata = unserialize($row-&gt;user_data);
              /* put data in array using username as key */
              $user['user_name'] = $udata['user_name']; 
              $user['is_logged_in'] = $udata['is_logged_in']; 
          }
          return $user;
      }
  
      function create_member()
      {
  
          $this-&gt;db-&gt;where('user_name', $this-&gt;input-&gt;post('username'));
          $query = $this-&gt;db-&gt;get('membership');
  
          if($query-&gt;num_rows &gt; 0){
              echo '&lt;div class="alert alert-error"&gt;&lt;a class="close" data-dismiss="alert"&gt;×&lt;/a&gt;&lt;strong&gt;';
              echo "Username already taken";  
              echo '&lt;/strong&gt;&lt;/div&gt;';
          }else{
  
              $new_member_insert_data = array(
                  'first_name' =&gt; $this-&gt;input-&gt;post('first_name'),
                  'last_name' =&gt; $this-&gt;input-&gt;post('last_name'),
                  'email_addres' =&gt; $this-&gt;input-&gt;post('email_address'),          
                  'user_name' =&gt; $this-&gt;input-&gt;post('username'),
                  'pass_word' =&gt; md5($this-&gt;input-&gt;post('password'))                      
              );
              $insert = $this-&gt;db-&gt;insert('membership', $new_member_insert_data);
              return $insert;
          }
  
      }//create_member
  
      function login()
      {
  
          $this-&gt;db-&gt;where('user_name', $this-&gt;input-&gt;post('username'));
          $query = $this-&gt;db-&gt;get('membership');
  
          if($query-&gt;num_rows &gt; 0){
              echo '&lt;div class="alert alert-error"&gt;&lt;a class="close" data-dismiss="alert"&gt;×&lt;/a&gt;&lt;strong&gt;';
              echo "Username already taken";  
              echo '&lt;/strong&gt;&lt;/div&gt;';
          }else{
  
              $new_member_insert_data = array(
                  'first_name' =&gt; $this-&gt;input-&gt;post('first_name'),
                  'last_name' =&gt; $this-&gt;input-&gt;post('last_name'),
                  'email_addres' =&gt; $this-&gt;input-&gt;post('email_address'),          
                  'user_name' =&gt; $this-&gt;input-&gt;post('username'),
                  'pass_word' =&gt; md5($this-&gt;input-&gt;post('password'))                      
              );
              $insert = $this-&gt;db-&gt;insert('membership', $new_member_insert_data);
              return $insert;
          }
  
      }//create_member    
  }
  </code></pre>