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
Create Table
After we have created a table we will insert some data into this table. Like as in the following image:
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:
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:
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.
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.
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.
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.
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.
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.
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.
Output
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