title: Redirecting to another page after logging in Using CodeIgniter framework
body: <p>I created a Login controller and when I redirect to the home page of my site, it won't redirect to my view which is the index. </p>
  
  <p>Here is my controller (main.php):</p>
  
  <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
  class Main extends CI_Controller {
  
  public function __construct()
       {
         parent::__construct();
       }
  
  public function index()
  {
      $this-&gt;load-&gt;view('login');
  }
  
  public function validate_credentials () {
  
              $this-&gt;load-&gt;model("membership_model");
              $query = $this-&gt;membership_model-&gt;validate();
  
              if($query){
                  $data = array(
                      'username' =&gt; $this-&gt;input-&gt;post('username'),
                      'is_logged_in' =&gt; true
                  );
                  $this-&gt;session-&gt;set_userdata($data);
                  redirect('Main/homepage1', 'refresh');
              }
              else {
                  $this-&gt;index();
              }
          }
  
      public function homepage1 () {
          $this-&gt;load-&gt;view("index");
      }
  
  
    }
  </code></pre>
  
  <p>here is my form inside login_view.php</p>
  
  <pre><code>&lt;form class="form-login" method="post" name="redirect" action="&lt;?php echo site_url("Main/validate_credentials"); ?&gt;"&gt;
              &lt;h2 class="form-login-heading"&gt;sign in now&lt;/h2&gt;
              &lt;div class="login-wrap"&gt;
                  &lt;input type="text" class="form-control" placeholder="User ID" autofocus value="&lt;?php echo set_value('username'); ?&gt;" &gt;
                  &lt;br&gt;
                  &lt;input type="password" class="form-control" placeholder="Password"  value = "&lt;?php echo set_value('password'); ?&gt;"&gt;
                  &lt;label class="checkbox"&gt;
                      &lt;span class="pull-right"&gt;
                          &lt;a data-toggle="modal" href="login.php#myModal"&gt; Forgot Password?&lt;/a&gt;
  
                      &lt;/span&gt;
                  &lt;/label&gt;
                  &lt;button class="btn btn-theme btn-block" name="login" href="index.html" type="submit"&gt;&lt;i class="fa fa-lock"&gt;&lt;/i&gt; SIGN IN&lt;/button&gt;
               &lt;/div&gt;
  
               &lt;?php  $this-&gt;load-&gt;view("modals/forgot_pass_modal"); ?&gt;
  
            &lt;/form&gt;
  </code></pre>
  
  <p>and my model:</p>
  
  <pre><code>&lt;?php if( ! defined ('BASEPATH')) exit ('No direct script access allowed');
  
  class Membership_model extends CI_Model{
  
      public function __construct()
       {
         parent::__construct();
       }
  
      public function validate () {
          $this-&gt;db-&gt;where('admin_username', $this-&gt;input-&gt;post('username'));
          $this-&gt;db-&gt;where("admin_pword", md5($this-&gt;input-&gt;post("password")));
          $query = $this-&gt;db-&gt;get("administration");
  
          if($query-&gt;num_rows() == 1){
              return true;
          }
      }
  
  
  }
   ?&gt;
  </code></pre>
  
  <p>Can someone help me? Because It is my first time using this PHP framework and I really appreciate if you could help me out.</p>