title: How to redirect user depending on user type at time of login (codeigniter)
body: <p>I'm facing problem while redirecting my user according to its type. how can do it here's my code please suggest how to do it.</p>
  
  <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
  class VerifyLogin extends CI_Controller {
  
    function __construct()
    {
      parent::__construct();
    }
  
    function index()
    {
         $this-&gt;load-&gt;model('user','',TRUE);
  
      //This method will have the credentials validation
      $this-&gt;load-&gt;library('form_validation');
      $this-&gt;load-&gt;library('session');
  
      $this-&gt;form_validation-&gt;set_rules('username', 'Username','trim|required|xss_clean');
      $this-&gt;form_validation-&gt;set_rules('password', 'Password'
        'trim|required|xss_clean|callback_check_database');
  
        if($this-&gt;form_validation-&gt;run() == FALSE)
        {        
  
       //Field validation failed.&amp;nbsp; User redirected to login page
       validation_errors();
  
       $this-&gt;load-&gt;view('error');
    }
   else
    {
    //Go to private area
  </code></pre>
  
  <p>basically here I want to redirect if user is admin then redirect to admin page else redirect to home. How can I do this ???</p>
  
  <pre><code>        redirect('home', 'refresh');
       }
      }
  
  
     function check_database($password)
     {
      //Field validation succeeded.&amp;nbsp; Validate against database
        $username = $this-&gt;input-&gt;post('username');
  
         //query the database
         $result = $this-&gt;user-&gt;login($username, $password);
  
       if($result)
       {
        $sess_array = array();
         foreach($result as $row)
        {
         $sess_array = array(
       'id' =&gt; $row-&gt;id,
       'username' =&gt; $row-&gt;username
       );
       $this-&gt;session-&gt;set_userdata('logged_in', $sess_array);
  
          }
          return TRUE;
        }
      else
         {
           $this-&gt;form_validation-&gt;set_message('check_database', 'Invalid username or password');
           return false;
         }
       }  
       }
    ?&gt;
  </code></pre>