title: Codigniter: Display current user in homepage after log-in
body: <p>I want to ask how can I display the current user that has logged-in in my homepage.</p>
  <p>Here is my login view:</p>
  <pre><code>&lt;form action=&quot;login2&quot; method=&quot;POST&quot; id=&quot;log_form&quot; name=&quot;log_form&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt; 
                          &lt;div class=&quot;modal-body&quot;&gt;
                             &lt;div class=&quot;container&quot;&gt;     
                                &lt;div id=&quot;nav_log1&quot;&gt;
                                  Username: &lt;input type=&quot;text&quot; id=&quot;txt_user1&quot; name=&quot;txt_user1&quot; style=&quot;color: black;&quot;/&gt;
                                  Password: &lt;input type=&quot;password&quot; id=&quot;txt_pass1&quot; name=&quot;txt_pass1&quot; style=&quot;color: black;&quot;/&gt;
                                &lt;/div&gt;
                              &lt;/div&gt; &lt;!-- /container --&gt;
                          &lt;div class=&quot;modal-footer&quot; style=&quot;padding: 20px; margin-top: 20px;&quot;&gt;
                              &lt;button type=&quot;submit&quot; value=&quot;login&quot; id=&quot;btn_login&quot; class=&quot;btn btn-primary btn-sm&quot; name=&quot;btn_login&quot;&gt;Sign-In&lt;/button&gt;
                              &lt;button class=&quot;btn btn-warning btn-sm&quot; data-dismiss=&quot;modal&quot;&gt;Cancel&lt;/button&gt;
                          &lt;/div&gt;
                          &lt;/div&gt;
                       &lt;/form&gt;
  </code></pre>
  <p>Here is my model:</p>
  <pre><code>public function select_login($value2){
      $login_user = $this-&gt;db-&gt;select('*')
                             -&gt;from('tblusers')
                             -&gt;where('Username', $value2['txt_user1'])
                             -&gt;where('Password', $value2['txt_pass1'])
                             -&gt;get()-&gt;row();
             return $login_user;
  }
  </code></pre>
  <p>And here is the controller that corresponds to the action of my form in my view:</p>
  <pre><code> public function login2(){
      $data = array();
      if(!empty($_POST['btn_login'])){
  
          $session_login = $this-&gt;inventory_model-&gt;select_login($this-&gt;input-&gt;post());
          if($session_login){
              $this-&gt;session-&gt;set_userdata('login_session', array('Username' =&gt; $session_login-&gt;Username,
                                                                  'Password' =&gt; $session_login-&gt;Password,
                                                                  'UserType' =&gt; $session_login-&gt;UserType));
                                                              redirect('inventorysys_controller/homepage');
          }
          else{
              $this-&gt;session-&gt;set_flashdata('msg','Invalid Username/Password!');
              redirect('inventorysys_controller/loginpage2');
          }
      }
  }
  </code></pre>
  <p>As you can see there is a <code>redirect('inventorysys_controller/homepage');</code> in my login2 controller. There are two views on that page since I am loading multiple views on my webpage. I will only post the header view since that's where I want to put the name of the user that has logged-in. Here is the view:</p>
  <pre><code>&lt;div class=&quot;container&quot;&gt;
    &lt;div class=&quot;masthead&quot;&gt;
      &lt;h3 class=&quot;text-muted&quot;&gt;Inventory System&lt;/h3&gt;&amp;nbsp;
      &lt;ul class=&quot;nav navbar-default nav-justified&quot;&gt;
        &lt;li&gt;&lt;a href=&quot;&lt;?php echo site_url('inventorysys_controller/homepage'); ?&gt;&quot;&gt;Home&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;&lt;?php echo site_url('inventorysys_controller/inventory'); ?&gt;&quot;&gt;Inventory&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;&lt;?php echo site_url('inventorysys_controller/userslist1'); ?&gt;&quot;&gt;Users List&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;&lt;?php echo site_url('inventorysys_controller/view_employees'); ?&gt;&quot;&gt;Employee&lt;/a&gt;&lt;/li&gt;
        &lt;li class=&quot;dropdown&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;dropdown-toggle&quot; id=&quot;dropdownMenu1&quot; data-toggle=&quot;dropdown&quot;&gt;Administration&lt;span class=&quot;caret&quot;&gt;&lt;/span&gt;&lt;/a&gt;
          &lt;ul class=&quot;dropdown-menu&quot; role=&quot;menu&quot; aria-labelledby=&quot;dropdownMenu1&quot;&gt;
              &lt;li role=&quot;presentation&quot;&gt;&lt;a role=&quot;menutitem&quot; tab-index=&quot;-1&quot; href=&quot;&lt;?php echo site_url('inventorysys_controller/maintenance'); ?&gt;&quot;&gt;Inventory Maintenance&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
        &lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;&lt;?php echo site_url('inventorysys_controller/about') ?&gt;&quot;&gt;About&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a name=&quot;btn_logsouts&quot; id=&quot;btn_logsouts&quot; href=&quot;&lt;?php echo site_url('inventorysys_controller/logsouts') ?&gt;&quot;&gt;&lt;span class='glyphicon glyphicon-off'&gt;&lt;/span&gt;&amp;nbsp;Logout&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
   &lt;/div&gt;
  </code></pre>
  <p>Here is a print screen of my homepage view for you to get my question:</p>
  <p><img src="https://i.stack.imgur.com/U2S3O.jpg" alt="enter image description here" /></p>
  <p>So that's it, I just want to select the username that has logged-in and show it on my homepage. I know I will create another query like <code>SELECT * FROM 'tblusers' where 'user' = --blank--</code>. I just don't know how to deal with that yet. Please help me guys! Thank you in advance for your help! :)</p>