Javatpoint Logo
Javatpoint Logo

Login page (with database)

In earlier example, we learnt a simple login page with one single username and session.

Now we'll make it with more than one users using database. A sign in and login page will be there for users.

Following pages are made in this example.

In application/controllers

  • Main.php

In application/views

  • login_view.php
  • invalid.php
  • data.php
  • signin.php

In application/models

  • login_model.php

In the first page, you'll have the option for Login and Sign In.

On Login, if user has entered correct credentials matching to database then he will be directed to data.php page. But if he has entered wrong information then incorrect username/password message will appear.

We have named our CodeIgniter folder as login_db. And our table name is signup.

Login page 1

We need to do some basic settings in our login_db CodeIgniter folder.

Go to autoload.php file, and do the following settings.

Login page 2

In the above snpashot, we have loaded the libraries and helper.

In database.php file, fill your username and database name. Our database name is codeigniter.

Login page 3

Now, we?ll start the example.

We have made file Main.php in application/controllers folder,

In application/views folder, login_view.php file is made.

In application/views folder, data.php file is made.

In application/views folder, signin.php file is made.

In application/views folder, invalid.php file is made.

In application/models folder, login_model.php file is made.

On entering the URL, http://localhost/login_db/index.php/Main/

Following page will appear.

Login page 4

Enter the information to Login.

Login page 5

After entering information, click on Login button. We have entered the wrong information and hence it will show the error message as shown below.

Login page 6

On entering the information from database, we' ll be directed to data.php page.

Login page7

Click on Login button.

Login page8

Clicking on Logout button, you'll be directed to the Main page.

On clicking Sign In, following page will appear.

Login page9
Login page10
Login page11



Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


B.Tech / MCA