title: code for login form in codeigniter
body: <p>I'm still learning my way around in CodeIgniter.</p>
  
  <p>I'd like to create a login form in my codeigniter application.
  My view section is below:</p>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;    
      &lt;title&gt;Jotorres Login Screen | Welcome &lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div id='login_form'&gt;
        &lt;form action="&lt;?php echo base_url();?&gt;Login/process" method='post' name='process' enctype="multipart/form-data"&gt;
          &lt;h2&gt;User Login&lt;/h2&gt;
          &lt;br /&gt;  
          &lt;?php if(! is_null($msg)) echo $msg;?&gt;   
          &lt;label for='username'&gt;Username&lt;/label&gt;
          &lt;input type='text' name='username' id='username' size='25' /&gt;&lt;br /&gt;
          &lt;label for='password'&gt;Password&lt;/label&gt;
          &lt;input type='password' name='password' id='password' size='25' /&gt;&lt;br /&gt;                            
          &lt;input type='Submit' value='Login' /&gt;            
       &lt;/form&gt;
      &lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Controller section:</p>
  
  <pre><code>&lt;?php
  
    if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    /* Author: Jorge Torres
    * Description: Login controller class
    */
    {
      class Login extends CI_Controller{
  
        function __construct(){
            parent::__construct();
        }
  
  
        public function index($msg = NULL){
            // Load our view to be displayed
            // to the user
            $data['msg'] = $msg;
            $this-&gt;load-&gt;view('login_view', $data);
        }
  
  
        public function process(){
            // Load the model
            $this-&gt;load-&gt;model('login_model');
            // Validate the user can login
            $result = $this-&gt;login_model-&gt;validate();
            // Now we verify the result
            if(! $result){
                // If user did not validate, then show them login page again
                $msg = '&lt;font color=red&gt;Invalid username and/or password.&lt;/font&gt;&lt;br /&gt;';
                $this-&gt;index($msg);
            }else{
                // If user did validate, 
                // Send them to members area
                redirect('Home');
            }        
        }
      }
    }
  ?&gt;
  </code></pre>
  
  <p>Error Message:</p>
  
  <blockquote>
    <p>The requested URL /afi/Login/process was not found on this server.</p>
  </blockquote>
  
  <p>How can I resolve this error?</p>
  
  <p>Model section:</p>
  
  <pre><code>&lt;?php
  defined('BASEPATH') OR exit('No direct script access allowed');
  /* Author: Jorge Torres
   * Description: Login model class
   */
  class Login_model extends CI_Model{
      function __construct(){
          parent::__construct();
      }
  
      public function validate(){
          // grab user input
          $username = $this-&gt;security-&gt;xss_clean($this-&gt;input-&gt;post('username'));
          $password = $this-&gt;security-&gt;xss_clean($this-&gt;input-&gt;post('password'));
  
          // Prep the query
          $this-&gt;db-&gt;where('username', $username);
          $this-&gt;db-&gt;where('password', $password);
  
          // Run the query
          $query = $this-&gt;db-&gt;get('users');
          // Let's check if there are any results
          if($query-&gt;num_rows == 1)
          {
              // If there is a user, then create session data
              $row = $query-&gt;row();
              $data = array(
                      'userid' =&gt; $row-&gt;userid,
                      'fname' =&gt; $row-&gt;fname,
                      'lname' =&gt; $row-&gt;lname,
                      'username' =&gt; $row-&gt;username,
                      'validated' =&gt; true
                      );
              $this-&gt;session-&gt;set_userdata($data);
              return true;
          }
          // If the previous process did not validate
          // then return false.
          return false;
      }
  }
  ?&gt;
  </code></pre>