How to Create a Secure php Login Page: Friends, in this article today we are learn how to make a login page using PHP with MySQL database. We can make a login page different way using PHP.
We need to use CSS code and HTML code to create the login page. Only the login tester template or design using these two codes. We will do the operational work of logging page of this article by pop.
Also Read: How to setup SEO code for html Website – Full Guideline
Also Read: php session Code not Working on Live Server – error Fix
But not only login page can be created with PHP, this login page can be created with JavaScript and other languages or coding.How to Create a Secure php Login Page.
On the login page we will use two input fields here one is username and the other is password. You can increase or decrease the amount of input field on the login page as per your requirement.
what is the PHP ?
php full form is Hypertext Processor. PHP server-side coding language. You must have a server to run this page. The server may be your live-server or your localhost server. Using this php cord we can do almost all types of mathematical programming very easily. Mathematically meant here, we can use php in all the places where we need logical programming.

Also Read: php Registration Form with Database Code – Signup Form in php
Example- Which of the two numbers is the larger number? This type of arithmetic calculation can be done very easily by php.
Here are the things you need to do to create a login page
First we will create a database. We will create it in MySQL database. You can use localhost server as live-server. I will use a live-server here. php login, php code for login.
Since we are learning in this article how to create a login page, we will only discuss the login issue here. You can manually add some user details in your database such as name, date of birth, email id, password etc.
Create a MySQL database
You can manually create MySQL database tables or you can create MySQL databases with SQL code. If you want to create a database table with SQL code, copy and paste the following code into your notepad and save it name the “user_details“.
CREATE TABLE IF NOT EXISTS `user_details` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`fName` varchar(100) NOT NULL,
`lName` varchar(100) NOT NULL,
`email` varchar(100) NOT NULL,
`password` varchar(500) NOT NULL,
`birthdate` text NOT NULL,
`gender` varchar(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
Create a Login Page
From the login page we will create here using HTML code. If you want you can make the login page with php code.
Also Read: 20 Questions – AdSense Approval Related for 100% AdSense Approval
Since we are discussing how php stands on how the login page works, we are not doing a nice design from the login page. The only basic thing I need to do is use the code for the login page. You can customize your loging page to suit your needs.
<form action="login-process.php" method="POST">
<input type="text" name="username" placeholder="Enter Email Id" required>
<input type="text" name="password" placeholder="Enter Password" required>
<input name="submit" type="submit">
</form>
Open your notepad, copy this code and paste it in notepad. Then save this page and name it “login.php“.
We are submit login form using “POST” method (<form action=”” method=”POST”>). and action page is login-process.php (<form action=”login-process.php“ method=”POST”>).
Create Database Connect page
Open your notepad add new page, copy this code and paste it in notepad. Then save this page and name it “dbcon.php“.
<?php
$server = "localhost";
$username = "user_details_root";
$password = "user@yegsgsr1548";
$database = "user_details";
// Create connection and Check connection
$conn = mysqli_connect($server, $username, $password) or die("Error in connection!");
mysqli_select_db($conn, $database ) or die("Could not select database");
?>
Here i am use live server. I need Database Username and Password ($username = “user_details_root”; $password = “user@yegsgsr1548”;)
if you used localhost server then default username is “route” and password is blank ($username = “root”; $password = “”;)
Create a Login Process Page
Open your notepad add new page, copy this code and paste it in notepad. Then save this page and name it “login-process.php“.
<?php
error_reporting(0);
include('dbcon.php'); // Its connection with database-----
$username = $_POST['username'];
$password = $_POST['password'];
if($_POST['email'])
{
if($_POST['password'])
{
$sql = ("SELECT * FROM user_details WHERE email ='$username'");
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result))
{
$dbemail = $row['email'];
$hash_from_database = $row['password'];
}
if (!password_verify($login_password, $hash_from_database))
{
echo"<font color='red'>You are enter Wrong Password</font>";
exit;
}
session_start();
$_SESSION['dbemail'] = $dbemail;
echo"<font color='green'>Login Sucessfully...</font>";
echo "<script>location='welcome.php'</script>";
exit();
}
else
{
echo"<font color='red'>Mobile No Doesn`t Exist !</font>";
}
}else
{
echo"<font color='red'>[ Note : - Enter Password ! ]</font>";
}
}else
{
echo"<font color='red'>[ Note : - Enter Your Mobile No ! ]</font>";
}
?>
Also Read: How to Increase Traffic on Blog Website 2022
Create Welcome page
Open your notepad add new page, copy this code and paste it in notepad. Then save this page and name it “welcome.php“.
<?php
session_start();
$_SESSION = $_SESSION['dbemail'];
if($_SESSION['dbemail'])
{
echo"Wel come - ".$_SESSION."";
}
?>
After session start in your welcome page you can customize your welcome page as per your requirement. If you want to show username, Full name, date of birth, email id, etc you can customize it.
Some Words
Here’s how to create a login page using php. In today’s article we learned the basics. If you need any kind of design then you have to make it to your needs. In this article we have discussed all those things which is important to create a page login page using php, I hope your php login, php code for login, subjects is completely cleared.
if you have face any problem or error for this login code, comments with your error or problem. we will fix your error as soon as possible.