Login Page With CodeIgniter Framework in PHP


In the previous article you saw how to fetch data from a MySQL database through the CodeIgniter framework in PHP. In this article you will see how to build a LogIn page with the CodeIgniter framework in PHP.

First of all we will create a database and table in MySQL. Suppose we created the "Company" database and "users" table in MySQL. There are the two fields, username and word in the users table.

Create Database

1st.jpg

Create Table

2nd.jpg

After we have created a table we will insert some data into this table. Like as in the following image:

3rd.jpg

After inserting data into the table in MySQL we will set the database configuration in the CodeIgniter framework. For the database configuration we will go to c:\xampp\htdocs\CodIgniter\application\config\database.php. Then we will write the following code in the database.php file:

4th.jpg

After configuration of the database in the CodeIgniter framework we will set the controller function. To set the controll function we will go to c:\xampp\htdocs\CodIgniter\application\config\routes.php. Then write the following code in the controller.php:

5th.jpg

After setting the controller we will configure the default libraries you want to load in all your controllers. To configure the libraries we will go to: c:\xampp\htdocs\CodIgniter\application\config\autoload.php.

6th.jpg

When you use the session library, you need to set the encryption_key and base_url. To set the encryption_key and base_url we will go to: c:\xampp\htdocs\CodIgniter\application\config\config.php.

7th.jpg

8th.jpg
Now we will create a model to select the data from the database. We will write the following code in the PHP file then save it in the
c:\xampp\htdocs\CodIgniter\application\models\user.php.

9th.jpg

After creating the user.php models we will create a controller. To create the controller we will write the following code in the PHP file then save in the c:\xampp\htdocs\CodIgniter\application\controllers\login.php.

10th.jpg

After creating the login controller we will create the home controller. To create the home controller we will write the following code in the PHP file then save in the c:\xampp\htdocs\CodIgniter\application\controllers\home.php.

homecontroller.jpg

After creating the home controller we will create a view file. To create the view file we will write the following code in the PHP file then save in the c:\xampp\htdocs\CodIgniter\application\controllers\login_view.php.
11th.jpg

After create the login_view.php file we will create the home view file. For create the home view file we will write the following code on PHP file then save in the c:\xampp\htdocs\CodIgniter\application\controllers\home_view.php.

12th.jpg

Output

13th.jpg

14th.jpg

15th.jpg

Conclusion

So in this article you saw how to create a login page with the CodeIgniter framework in PHP. Using this article one can easily understand how to create a login page with the CodeIgniter framework in PHP.

Some Helpful Resources


Similar Articles