How to Create Login Form in CodeIgniter, MySQL and Twitter Bootstrap

Hi I'm back with CodeIgniter Bootstrap Login Tutorial. In this post, we'll see How to Create Login Form in CodeIgniter and Bootstrap Framework along with MySQL Database. Similar to other articles in our codeigniter tutorial series, here too we use twitter bootstrap css to design user interface. Twitter Bootstrap has ready to use HTML Form Components which we use to style our codeigniter login form in seconds.

To create codeigniter login page, I'm going to use MySQL as backend but you can switch over it to any other relational DBMS. Just change over database connection settings in codeigniter config file and you are done!

Creating CodeIgniter Login Form

Before heading to write any code for the login form in codeigniter, we'll fix the MySQL Database we need to use in our example.

Don't Miss: Codeigniter Login, Logout & Sigup System using MySQL & Bootstrap

Create MySQL Database

DB Name: Employee

Table Name: tbl_usrs

CREATE TABLE IF NOT EXISTS `tbl_usrs` (
  `id` int(8) NOT NULL AUTO_INCREMENT,
  `username` varchar(30) NOT NULL,
  `password` varchar(40) NOT NULL,
  `email` varchar(60) NOT NULL,
  `status` varchar(8) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

INSERT INTO `tbl_usrs` (`username`, `password`, `email`, `status`) VALUES
('admin', '21232f297a57a5a743894a0e4a801fc3', 'admin@mydomain.com', 'active');

Run this SQL Command in MySQL Database to create the users table required for the codeIgniter bootstrap login system.

Note: The above sql statement will create the table with a sample user record for testing. The password has been md5 'ed and stored in the db. Use this login credentials for testing purpose, username: admin password: admin

Login Form in CodeIgniter, MySQL and Bootstrap

Here is the Flow for the Login Form in CodeIgniter and Bootstrap we are going to build.

  1. User enters the username and password.
  2. Read database & check if an active user record exists with the same username and password.
  3. If succeeds, redirect user to the Main/Home Page.
  4. If it fails, show ERROR message.

Also Read: CodeIgniter Database CRUD Operations for Absolute Beginners

The Model

First create the model file for login form in codeigniter with name "login_model.php" in the "application/models" folder.

login_model.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class login_model extends CI_Model
{
     function __construct()
     {
          // Call the Model constructor
          parent::__construct();
     }

     //get the username & password from tbl_usrs
     function get_user($usr, $pwd)
     {
          $sql = "select * from tbl_usrs where username = '" . $usr . "' and password = '" . md5($pwd) . "' and status = 'active'";
          $query = $this->db->query($sql);
          return $query->num_rows();
     }
}?>

The Controller

Next create the controller for our codeigniter login form with the name "login.php" in the "application/controllers" folder.

login.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class login extends CI_Controller
{

     public function __construct()
     {
          parent::__construct();
          $this->load->library('session');
          $this->load->helper('form');
          $this->load->helper('url');
          $this->load->helper('html');
          $this->load->database();
          $this->load->library('form_validation');
          //load the login model
          $this->load->model('login_model');
     }

     public function index()
     {
          //get the posted values
          $username = $this->input->post("txt_username");
          $password = $this->input->post("txt_password");

          //set validations
          $this->form_validation->set_rules("txt_username", "Username", "trim|required");
          $this->form_validation->set_rules("txt_password", "Password", "trim|required");

          if ($this->form_validation->run() == FALSE)
          {
               //validation fails
               $this->load->view('login_view');
          }
          else
          {
               //validation succeeds
               if ($this->input->post('btn_login') == "Login")
               {
                    //check if username and password is correct
                    $usr_result = $this->login_model->get_user($username, $password);
                    if ($usr_result > 0) //active user record is present
                    {
                         //set the session variables
                         $sessiondata = array(
                              'username' => $username,
                              'loginuser' => TRUE
                         );
                         $this->session->set_userdata($sessiondata);
                         redirect("index");
                    }
                    else
                    {
                         $this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Invalid username and password!</div>');
                         redirect('login/index');
                    }
               }
               else
               {
                    redirect('login/index');
               }
          }
     }
}?>

The View

Finally create the view file with name "login_view.php" in the folder "application/views". Here is where we integrate bootstrap with codeigniter php framework and add HTML tags to create the actual login form in the codeigniter view.

login_view.php
<!DOCTYPE html>
<html>
<head>
     <meta charset="utf-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <title>Login Form</title>
     <!--link the bootstrap css file-->
     <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
     
     <style type="text/css">
     .colbox {
          margin-left: 0px;
          margin-right: 0px;
     }
     </style>
</head>
<body>
<div class="container">
     <div class="row">
          <div class="col-lg-6 col-sm-6">
               <h1>LIVEDOTCOM</h1>
          </div>
          <div class="col-lg-6 col-sm-6">
               
               <ul class="nav nav-pills pull-right" style="margin-top:20px">
                    <li class="active"><a href="#">Login</a></li>
                    <li><a href="#">Signup</a></li>
               </ul>
               
          </div>
     </div>
</div>
<hr/>

<div class="container">
     <div class="row">
          <div class="col-lg-4 col-sm-4 well">
          <?php 
          $attributes = array("class" => "form-horizontal", "id" => "loginform", "name" => "loginform");
          echo form_open("login/index", $attributes);?>
          <fieldset>
               <legend>Login</legend>
               <div class="form-group">
               <div class="row colbox">
               <div class="col-lg-4 col-sm-4">
                    <label for="txt_username" class="control-label">Username</label>
               </div>
               <div class="col-lg-8 col-sm-8">
                    <input class="form-control" id="txt_username" name="txt_username" placeholder="Username" type="text" value="<?php echo set_value('txt_username'); ?>" />
                    <span class="text-danger"><?php echo form_error('txt_username'); ?></span>
               </div>
               </div>
               </div>
               
               <div class="form-group">
               <div class="row colbox">
               <div class="col-lg-4 col-sm-4">
               <label for="txt_password" class="control-label">Password</label>
               </div>
               <div class="col-lg-8 col-sm-8">
                    <input class="form-control" id="txt_password" name="txt_password" placeholder="Password" type="password" value="<?php echo set_value('txt_password'); ?>" />
                    <span class="text-danger"><?php echo form_error('txt_password'); ?></span>
               </div>
               </div>
               </div>
                              
               <div class="form-group">
               <div class="col-lg-12 col-sm-12 text-center">
                    <input id="btn_login" name="btn_login" type="submit" class="btn btn-default" value="Login" />
                    <input id="btn_cancel" name="btn_cancel" type="reset" class="btn btn-default" value="Cancel" />
               </div>
               </div>
          </fieldset>
          <?php echo form_close(); ?>
          <?php echo $this->session->flashdata('msg'); ?>
          </div>
     </div>
</div>
     
<!--load jQuery library-->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!--load bootstrap.js-->
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
</body>
</html>

Note: You can load Bootstrap files from CDN to load faster. Include jQurey.js prior to bootstrap.js files as they depend on jQuery library.

Must Read: CodeIgniter User Registration Page with Email Confirmation

Have any problem in implementing this login form in codeigniter, bootstrap and mysql? Got some suggestion for improvement? Let me know through your comments.

Look into our CodeIgniter Tutorials Section for more advanced articles.

Last-Modified: Dec-24-2016

106 comments:

  1. Hi there,
    I'm new in codeigniter & bootstrap, but after installation of these tutorial pages, I've this error:

    Fatal error: Call to undefined function form_open() in C:\inetpub\wwwroot\newportal\application\views\login_view.php on line 40

    Please help me!!
    Thanks in advance.
    Antonio

    ReplyDelete
    Replies
    1. Hi, it seems like codeigniter's form helper is not loaded properly. Please make sure you have included it inside the controller's constructor function like this.

      class login extends CI_Controller
      {
      public function __construct()
      {
      parent::__construct();

      ...

      $this->load->helper('form');

      ...
      }
      }

      Hope this helps :)

      Delete
    2. Hi, unfortunatly this code is just into the controller, so the error persist.
      Have you any others ideas?
      Thanks,
      Antonio

      Delete
    3. Hi, you can try auto loading the helpers and libraries in the 'application\config\autoload.php' file like this,

      $autoload['helper'] = array('form', 'url', 'html');
      $autoload['libraries'] = array('database', 'session', 'form_validation');

      Delete
    4. autoload worked thanks a lot

      Delete
    5. i'm follow this steps but not solve my error...Help Me plz..!!

      Delete
    6. I'm Follow this steps but not solve my error..Please Help Me...!!

      Delete
  2. why i got error from this code after follow all of ur instructions
    " "form-horizontal", "id" => "loginform", "name" => "loginform");
    echo form_open("login_c/index", $attributes);
    ?>"

    The error appear like this "The requested URL /.../login_c/index was not found on this server."

    can you please help me.

    ReplyDelete
    Replies
    1. Hi! Using wrong path to run a controller will throw such error. Try to run the file like this,

      http://localhost/codeigniter_demo/index.php/login

      (assuming you run this in localhost)

      where 'codeigniter_demo' is the codeigniter app (folder) name,
      'login' is the name of the controller class (ie., which you have used in this code => class login extends CI_Controller)

      Note: If you have your app folder in different location, then use the exact location to run the file. As a rule of thumb the path should be like this,

      http://localhost/path/to/codeigniter_app/index.php/controller_class_name

      Cheers.

      Delete
  3. Error Number: 1054

    Unknown column 'var_username' in 'where clause'

    select * from tbl_usrs where var_username = test and var_password = 098f6bcd4621d373cade4e832627b4f6 and var_status = 'active'

    Filename: models/Login_model.php

    Line Number: 15

    what is wrong ?

    ReplyDelete
  4. Hi, there was some db table column name mismatch error in the model query. Thanks for bringing out... I have corrected it. It should work now :)

    Cheers!!

    ReplyDelete
  5. Thanks for the collaboration Valli. There some details that needs to be fixed in the example in order to work:

    1. Rename: login_model.php to Login_model.php (caps)
    2. Rename: login.php to Login.php (caps)
    3. Is better to let the framework to handle the query. Change the 3 lines of the query in Login_model.php for the following:

    $this->db->where('username', $usr);
    $this->db->where('password', md5($pwd));
    $query = $this->db->get('users');
    return $query->num_rows();


    Hope this helps.

    ReplyDelete
    Replies
    1. Hi, thanks for your input. Yep! It's a good practice to stick on to the frameworks db handling features. But it's not necessary for the file names to start with caps although ci suggests naming the controller class names starting with caps. CI itself is somewhat inconsistent with naming convention rules and there aren't much. Irrespective of using upper or lower case namings, the above code works if you access the controller with the proper url.

      Hope that helps :-)

      Delete
    2. It worked, and no errors but where do I have to put the "status=' ' " part in the scripts above?

      And also I can't login, always result invalid login name and password.

      Delete
    3. Hi, 'status' is a column name present in the db table and it should be set as active to allow the particular user to login to the site (useful for membership websites).

      And the answer for the second question is you should create a valid db table with field values and then use those login credentials with the script. Then it will work.

      Cheers.

      Delete
    4. A Database Error Occurred

      Error Number: 1146

      Table 'mathevent.tbl_usrs' doesn't exist

      select * from tbl_usrs where username = 'supriamir' and password = '65a4e5c03f7ce2a21538ceafa46b8c6a' and status = 'active'

      Filename: models/Login_model.php

      Line Number: 16


      Hi there, I get this error. I do i fix this. Before I already had mathevent database.

      Thanks
      Supri

      Delete
  6. An Error Was Encountered

    Unable to load the requested file: Login_view.php
    What's wrong? Please help!

    ReplyDelete
  7. An Error Was Encountered

    Unable to load the requested file: Login_view.php
    What's wrong? Please help!

    ReplyDelete
  8. An Error Was Encountered

    Unable to load the requested file: Login_view.php
    What's wrong? Please help!

    ReplyDelete
    Replies
    1. Hi !! File names are case sensitive. Please check you use the same case as in view folder.

      if you have the file as Login_view.php then load the view in controller as,

      $this->load->view('Login_view');

      Hope this helps :)

      Delete
  9. The requested URL /newpro/login/index was not found on this server.

    what is error..


    ReplyDelete
    Replies
    1. Hi! CI follows a url structure like below unless you specifically rewrite the urls with htacess file.

      [base_url] / index.php / [controller_name] / [controller_function_name]

      So say if I have an app folder with name 'cidemo' and I want to access a controller with file name 'login.php' and class name of 'login', then I access it in localhost like,

      http://localhost/cidemo/index.php/login

      The default function called in controller is index(), so you need not specify it in the url.

      I hope this helps :)

      Delete
  10. Im getting this error pls help me....


    A Database Error Occurred

    Error Number: 1054

    Unknown column 'eranda' in 'where clause'

    select * from tbl_usrs where username = eranda and password = 202cb962ac59075b964b07152d234b70 and status = 'active'

    Filename: /var/www/CI/models/login_model.php

    Line Number: 15

    ReplyDelete
    Replies
    1. Hi! Since the username and password fields are both strings use quotes in the sql query like this,

      $sql = "select * from tbl_usrs where username = '" . $usr . "' and password = '" . md5($pwd) . "' and status = 'active'";

      This should work :)

      Delete
  11. Hi,
    I can`t login. Invalid username and password!
    How can I add user to database ? Password field in database must be md5 sum or plain text?

    ReplyDelete
  12. Hi! A valid user record should be present in the db for the login script to work. Usually for membership sites, the user records will be inserted with the sign up (registration) form. And yes the password should be md5 encrypted and stored in the db.

    Note: For testing this script you can just insert some user data to the db using mysql gui like phpmyadmin.

    Cheers.

    ReplyDelete
  13. hey why don't you provide demo of the example ..!
    also you can provide code in zip format...!
    that make everyone life easy... :)

    hope this help everyone...!

    ReplyDelete
  14. Unable to locate the specified class: Session.php

    ReplyDelete
    Replies
    1. This problem occurs when you try to call session library without loading it.

      You should either load the session library inside the controller's constructor like this,

      $this->load->library('session');

      or you should auto load it inside the file, application >> config >> autoload.php like this,

      $autoload['libraries'] = array('session', 'database', 'form_validation');

      Either way it works :)

      Delete
  15. its not connecting to the database?

    ReplyDelete
    Replies
    1. Please check this tutorial to properly configure and set up database connection in codeigniter.

      http://www.kodingmadesimple.com/2015/05/install-setup-php-codeigniter-framework-xampp-localhost.html

      Hope this helps :-)

      Delete
  16. Error Number: 1064

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''aa47f8215c6f30a0dcdb2a36a9f4168e' at line 1

    select * from admin where username='daniel' and password='aa47f8215c6f30a0dcdb2a36a9f4168e

    Filename: C:\AppServ\www\TA\system\database\DB_driver.php

    Line Number: 330

    my sintax : $sql = "select * from admin where username='".$username."' and password='".md5($pass);

    any wrong with my syntax? tq before :)

    ReplyDelete
    Replies
    1. Hi! Change the sql statement like this,

      $sql = "select * from admin where username='".$username."' and password='".md5($pass)."'";

      You have missed out the closing quotes.
      Cheers.

      Delete

    2. Just delete md5 from code, i did it and it worked...

      Delete
  17. Can i ask how does one check on a page if your loged in or not ie to create a logout link

    ReplyDelete
    Replies
    1. Hi, during login process you have to save the user details & logged in status within session like this,

      $data = array(
      'user_id' => $id,
      'user_name' => $name,
      'is_logged_in' => TRUE
      );
      $this->session->set_userdata($data);

      Then you can check out if the user is logged in or not like this,

      if ($this->session->userdata('is_logged_in') == TRUE)
      {
      // logged in
      }
      else
      {
      // not logged in
      }

      Also make sure to load the session library for this to work.

      Hope this helps :)

      Cheers.

      Delete
    2. hey, how do you echo out the username when your logged in? sorry... i'm new to this

      Delete
    3. During login process we store the 'username' in session variable. So you can use echo $this->session->userdata('username'); anywhere you want to display the logged-in username. The session data will be maintained until the user logs out.

      Cheers.

      Delete
  18. Hi, Excellent article.
    I am a noob and would like to know how do we integrate this user table into the db - do we add it to whatever app we have as a separate stand-alone table?

    ReplyDelete
    Replies
    1. Hi! This example uses MySQL DB. You have to create a database with name 'employee' and run the sql command given in the tutorial in MySQL. It'll automatically creates the required table structure.

      Cheers.
      Valli.

      Delete
  19. Replies

    1. I'm glad you liked it! Thanks for your support.

      Cheers
      Valli.

      Delete
  20. Hi, i've followed this tutorial and the previous one to remove the 'index.php' from the URL. The problem is, when i tried to run the login page with http://localhost/ci_demo/login as the address, it redirects to XAMPP home page instead. I've also tried with http://localhost/ci_demo/index.php/login but it showed me the 404 message. Am i missing something here? :(

    ReplyDelete
  21. This comment has been removed by the author.

    ReplyDelete
  22. Hello
    Thank you a lot for your article, it really helped me a lot.
    I have a strange problem here. When I load the page, it loads only till <php, and then - nothing.
    The only difference from your files is that I have header in separate file, so I'm including it with php also. And it works, so php itself is running.
    But even if I copy your code, the result is the same - these php functions are just not running. Do you have an idea what the reason may be? Thanks

    ReplyDelete
    Replies
    1. Hi! It's difficult to fix the problem without seeing your code. Any how I commonly see some people using opening & closing html tags on both views if they split up the header in a separate file.

      Make sure your header contains up to closing head tag and the body element & closing html tags are present in the other view file.

      I hope this makes sense.

      Cheers.

      Delete
  23. Hi, I've followed all your instructions but whenever I log in it always tells me that I have an invalid username and password

    ReplyDelete
  24. Hi, I've followed all your instructions but whenever I log in it always tells me that I have an invalid username and password

    ReplyDelete
    Replies
    1. Hi! You must have at least one user record in the database for the login process to work. Inserting some data and try out. Please note the password field is md5 and stored in database.

      Check out this user registration tutorial first to know more,
      http://www.kodingmadesimple.com/2015/08/create-simple-registration-form-codeigniter-email-verification.html

      Hope this helps!

      Cheers.

      Delete
    2. i have the same problem... i have set up my database and table with md5 and still doesn't work.. plzzzzz help!!!

      Delete
    3. Hi! I have updated the tutorial with user records for testing purpose. Please check it out.

      Delete
    4. Hi! After im trying to login and failed. something wrong. You need to edit column password . Chage varchar(30) to varchar(35).

      Delete
    5. Increasing the password column length in database will fix the issue. I have updated the post. Please check it out.

      Cheers.

      Delete
  25. guys add this in the controller contructor
    $this->load->library('form_validation');
    if not working!

    ReplyDelete
  26. Hi, great article,
    i found one error in db structure.
    The password field of database [`password` varchar(30)] should be longer. In fact when i try to insert the MD5 value it's truncated. the field should be 32 char long at least.
    cheers

    ReplyDelete
    Replies
    1. Thanks for your input. The password length has been gn wrong somehow. I'll fix it.

      Delete
  27. i couldnot login. Always shows invalid username and password/

    ReplyDelete
    Replies
    1. Sorry! Just increase the password field length to 40 chars or more in database. That will fix the issue.

      Cheers.

      Delete
  28. When i click in login, the page redirect me to a blank page !
    How can i fix it ?

    ReplyDelete
    Replies
    1. The scope of this tutorial is to show how to implement login page alone in a site. But in real world application, after successful login, the user should be redirected to some other pages like home or myaccount page. For that you have to build another controller for home page and redirect to it like this.

      redirect('home/index');

      Hope you get it right. Cheers.

      Delete
    2. hi, can you share some details, how to build another controller for home page?

      I am new, after username and password, see the following error:

      404 Page Not Found

      The page you requested was not found.

      I think its successfully logged in, but unable to find the next page.

      Delete
    3. Like I mentioned above, once your login is successful you can redirect user to home page. To create home page you atleast need a controller and a view. Look in our ci tutorials section to know about creating controllers. The process has been referred several times.

      Hope this helps.

      Delete
  29. Hey, thank you for the tutorial, but I cannot make it work. It just show me the LIVEDOTCOM title, the Login and Signup buttons and a disabled textbox. What am I doing wrong? I'v doubled check all the code to follow you tutorial even the comments...
    Help me, please!

    Thank you

    ReplyDelete
    Replies
    1. Can you copy paste your code in pastebin and provide me the link? I can check it out for you.

      Cheers.

      Delete
  30. In order to run your code in CI 3, we need to be change some things:
    1. create table ci_session
    CREATE TABLE IF NOT EXISTS `ci_sessions` (
    `id` varchar(40) NOT NULL,
    `ip_address` varchar(45) NOT NULL,
    `timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
    `data` blob NOT NULL,
    PRIMARY KEY (id),
    KEY `ci_sessions_timestamp` (`timestamp`)
    );
    2. Modify config.php
    $config['sess_driver'] = 'database';
    $config['sess_save_path'] = 'ci_session'; // table name ci_session

    ReplyDelete
  31. I get this error: In order to use the Session class you are required to set an encryption key in your config file.
    what should I do ?

    ReplyDelete
    Replies
    1. Codeigniter needs you to set encryption key if you use session library. By default it will be set to null string in config.php file. Just add some encryption key in the config file.

      $config['encryption_key'] = 'your encryption key here';

      This will fix the issue.
      Cheers.

      Delete
  32. Error Number: 1064

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `id` = '716995328b10b62fbec86969070e8f739dd4fadd'' at line 2

    SELECT `data` WHERE `id` = '716995328b10b62fbec86969070e8f739dd4fadd'

    Filename: libraries/Session/drivers/Session_database_driver.php

    Line Number: 166

    what about this? im using CI3

    ReplyDelete
    Replies
    1. It seems like ci tries to store session details in the db. If you are using CI3 and chose session driver as database, then make sure you have the following settings in the config.php file.

      $config['sess_driver'] = 'database';
      $config['sess_save_path'] = 'ci_sessions';

      Also check you have this mysql database table for storing session data.

      CREATE TABLE IF NOT EXISTS `ci_sessions` (
      `id` varchar(40) NOT NULL,
      `ip_address` varchar(45) NOT NULL,
      `timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
      `data` blob NOT NULL,
      KEY `ci_sessions_timestamp` (`timestamp`)
      );

      Here is the official documentation link for the setup.

      http://www.codeigniter.com/userguide3/libraries/sessions.html#database-driver

      Hope this helps!
      Cheers.

      Delete
  33. during redirect, baseurl is also taken. so redirect is not working.
    what can i do for that?

    ReplyDelete
  34. A Database Error Occurred

    Unable to select the specified database: employee

    Filename: C:\wamp\www\Ci_login_bootstrap\system\database\DB_driver.php

    Line Number: 141

    i had select the proper database.


    $db['default']['hostname'] = 'localhost';
    $db['default']['username'] = 'root';
    $db['default']['password'] = '';
    $db['default']['database'] = 'employee';

    please give me solution for this

    ReplyDelete
  35. A Database Error Occurred

    Unable to select the specified database: employee

    Filename: C:\wamp\www\Ci_login_bootstrap\system\database\DB_driver.php

    Line Number: 141

    i am done with all config of database still it is showing this error

    help me out from this

    ReplyDelete
  36. Hello Valli. I refer to your past tutorial 2 Step Registration with Email Verification http://www.kodingmadesimple.com/2015/08/create-simple-registration-form-codeigniter-email-verification.html The QUESTION is How can i check if my Account is activated? Example I login but my account is not Activated how can i check that???

    ReplyDelete
  37. Replies
    1. I'm considering... maybe in the near future:)

      Delete
  38. Hi ,I am getting this kind of error !
    Object not found!

    The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

    If you think this is a server error, please contact the webmaster.

    Error 404

    localhost
    Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.6.3

    ReplyDelete
  39. Object not found!

    The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

    If you think this is a server error, please contact the webmaster.

    Error 404

    localhost
    Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.6.3

    ReplyDelete
  40. when I press the url change to http://localhost/Codeigniter/login_view.php/login/index why? :(

    ReplyDelete
  41. when i click Login button entering 'admin' as username and password this error comes:
    Call to a member function get_user() on null
    please help :/

    ReplyDelete
  42. when i enter 'admin' as usernam and password this error is encounterd
    Call to a member function get_user() on null
    please help :/

    ReplyDelete
  43. Hi. I like your site it really useful to me as a beginners , anyway I'm so stock here when I login the username and password is going to login_form even though the username and password is not on databse w/c means is not matching ..

    http://localhost/test/index.php/login/index

    and when I login and login , the username and password is not validate . I mean NO Validation_errors(); says.


    thank you.

    ReplyDelete
  44. Hi. I like your site it really useful to me as a beginners , anyway I'm so stock here when I login the username and password is going to login_form even though the username and password is not on databse w/c means is not matching ..

    http://localhost/test/index.php/login/index

    and when I login and login , the username and password is not validate . I mean NO Validation_errors(); says.


    thank you.

    ReplyDelete
  45. Hi, I have a controller i need to protect it so that only logged users can view it
    how to achieve that i m new in codeigniter :)

    ReplyDelete
    Replies
    1. You can save user logged in status in session and check it to restrict access to any page like this,

      if ($this->session->userdata('is_logged_in') != TRUE)
      {
          // redirect user to home or whereever you want
      }

      Hope this helps! Cheers!!!

      Delete
  46. How can we ensure that the restricted pages are accessed directly? What code will go in header in such case?

    ReplyDelete
  47. How can we ensure that the restricted pages are accessed directly? What code will go in header in such case?

    ReplyDelete
  48. hi
    i am getting following error

    An uncaught Exception was encountered

    Type: RuntimeException

    Message: Unable to locate the model you have specified: Login_model

    Filename: /var/www/codeigniter/system/core/Loader.php

    Line Number: 314

    Backtrace:

    File: /var/www/codeigniter/application/controllers/Login.php
    Line: 8
    Function: __construct

    File: /var/www/codeigniter/index.php
    Line: 292
    Function: require_once

    please help

    ReplyDelete
  49. hi
    i am getting following error

    An uncaught Exception was encountered

    Type: RuntimeException

    Message: Unable to locate the model you have specified: Login_model

    Filename: /var/www/codeigniter/system/core/Loader.php

    Line Number: 314

    Backtrace:

    File: /var/www/codeigniter/application/controllers/Login.php
    Line: 8
    Function: __construct

    File: /var/www/codeigniter/index.php
    Line: 292
    Function: require_once

    ReplyDelete
  50. as I make a validation for multi users

    ReplyDelete
  51. as I make a validation for multi users

    ReplyDelete
  52. I can not log in although i create a db named 'ict_aissignment' which has admin user that has "admin" password. It still shows "invalid user".

    ReplyDelete
  53. Error Number: 1046

    No database selected

    select * from tbl_usrs where username = 'twinkal' and password = '48d7f9ee3d6c99ff1ab8542cc4359d12' and status = 'active'

    Filename: D:/xampp/htdocs/CI/form/system/database/DB_driver.php

    Line Number: 691
    please give the solution at twinkalkushwaha@gmail.com

    ReplyDelete
  54. After input username and password then click "Login" or press Enter, it redirect to localhost/xampp. Whats wrong with my code?

    ReplyDelete
  55. Hello. I used this code in my editor and this piece of code: "form-horizontal", "id" => "loginform", "name" => "loginform"); echo form_open("login/index", $attributes);?> is displaying in my login form page in browser. I read the comments above and i noticed that someone else had the same problem. I followed ur suggestions but nothing happened. Please help me!

    ReplyDelete
  56. Object not found!

    The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

    If you think this is a server error, please contact the webmaster.

    Error 404

    localhost
    Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/5.6.28

    ReplyDelete
  57. Object not found!

    The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

    If you think this is a server error, please contact the webmaster.

    Error 404

    localhost
    Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/5.6.28

    ReplyDelete
  58. display invalid username and password plz help me how to short this error in login page

    ReplyDelete
  59. in login_view.php when we enter username and password there is error invaild username and password plz help

    ReplyDelete
  60. how to fetch login user all data from database

    ReplyDelete
  61. how to fetch login user all data from database

    ReplyDelete
  62. Fatal error: Call to undefined function form_open() in E:\php\xampp\htdocs\ey_code\CodeIgniter\application\views\login_view.php on line 40


    also set helper properly

    ReplyDelete
    Replies
    1. Hi, seems like form helper error. Try autoloading the helpers and libraries in the 'application\config\autoload.php' file like this,

      $autoload['helper'] = array('form', 'url', 'html');
      $autoload['libraries'] = array('database', 'session', 'form_validation');

      Cheers.

      Delete
  63. Object not found!
    The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

    If you think this is a server error, please contact the webmaster.

    Error 404
    localhost
    Apache/2.4.29 (Win32) OpenSSL/1.1.0g PHP/7.2.1

    ReplyDelete