Hey, Guys Hope you all of fine, in this tutorial I’m going to teach you How to How to Make Login System in PHP with Validation. Login and also Registration System play important role in Web Application, So, I will teach you to step by step How You can Design Login Form and Also Registration Form in Bootstrap.
If you know Bootstrap working Process that great otherwise, I already publish complete Bootstrap 4. You can watch and get knowledge all about Bootstrap. Before watching Bootstrap 4 you must have Knowledge in HTML5, CSS3, and Also Little JavaScript.
If you want to use HTML5 and CSS3 to Design Login Form and Also Registration From. You can do that, but I will use Bootstrap classes to Design Login and Registration Form. So, let’s start to design the Login Form in PHP and Also Registration Form.

Registration and Login Form in Php and MySQL
First of All, I will be mentioned index.php Code. This Code has Two Files such as Header.php and Footer.php. You need to Copy that code and create Index.php and Paste the Code.
You May Also Like: School Management System in PHP
<?php require_once('header.php'); ?>
<h4 class="display-4 text-center mt-5">Home Page</h4>
<?php require_once('footer.php'); ?>
Then you need to Create Two Files Header.php and Footer.Php. I will be mentioned Header.php code on below, you can copy that and create Header.Php file and Paste it.
<?php session_start(); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="bootstrap/bootstrap.css">
<title>Login System in PHP</title>
</head>
<body style="background:#CCC;">
<nav class="navbar navbar-expand-sm navbar-dark bg-dark">
<div class="container">
<a href="index.php" class="navbar-brand"><h3>Login System</h3></a>
<div class="collapse navbar-collapse">
<ul class="nav navbar ml-auto">
<?php
if(isset($_SESSION['U_D']))
{
echo '<form action="includes/logout.php" method="POST">
<li class="nav-item"><button type="submit" name="logout" class="btn btn-outline-light">Logout</button></li>
</form>';
}
else
{
echo ' <li class="nav-item"><a href="logindesign.php" class="btn btn-outline-light">Login</a></li>
<li class="nav-item"><a href="signupdesign.php" class="btn btn-outline-light ml-3">Sign Up</a></li>';
}
?>
</ul>
</div>
</div>
</nav>
Then the next step is you need to create Footer.PHP file. In this file, you need to enter more two codes I mentioned below.
</body> </html>
Once you have successfully made the mentioned files and paste the codes. You need to Design Login Form, I mentioned LoginDesign.PHP Code on below, you can copy that and create a new file and paste the code.
You May Also Like: Best Php Scripts With Source Code
<?php require_once('header.php'); ?>
<div class="container">
<div class="row">
<div class="col-lg-6 m-auto">
<div class="card bg-light mt-5">
<div class="card-title bg-primary text-white mt-5">
<h3 class="text-center py-2">Login Form</h3>
</div>
<?php
if(isset($_GET['empty']))
{
$Message=$_GET['empty'];
$Message= " Please Fill in the Blanks";
?>
<div class="alert alert-danger text-center"><?php echo $Message ?></div>
<?php
}
?>
<?php
if(isset($_GET['U_Invalid']))
{
$Message=$_GET['U_Invalid'];
$Message= " Invalid User";
?>
<div class="alert alert-danger text-center"><?php echo $Message ?></div>
<?php
}
?>
<?php
if(isset($_GET['P_Invalid']))
{
$Message=$_GET['P_Invalid'];
$Message= " Invalid Password";
?>
<div class="alert alert-danger text-center"><?php echo $Message ?></div>
<?php
}
?>
<div class="card-body">
<form action="includes/login.php" method="POST" >
<input type="text" name="UserName" placeholder="Enter User Name or Email" class="form-control my-2">
<input type="password" name="password" placeholder=" Enter Your Password" class="form-control mb-3">
<button class="btn btn-success" name="login" class="pt-3">Login</button>
</form>
</div>
</div>
</div>
</div>
</div>
<?php require_once('footer.php'); ?>
Then, you need to Design Sign up Form So, You need to use the Same Process create signupdesign.php File and Paste the Code.
You May Also Like: Login Form in PHP with Session
<?php require_once('header.php'); ?>
<div class="container">
<div class="row">
<div class="col-lg-6 m-auto">
<div class="card bg-light mt-5">
<div class="card-title bg-primary text-white mt-5">
<h3 class="text-center py-2">Signup Form</h3>
</div>
<!--Display Empty Fiels-->
<?php
if(isset($_GET['empty']))
{
$Message=$_GET['empty'];
$Message=" Please Fill in the Blanks ";
?>
<div class="alert alert-danger text-center"><?php echo $Message?></div>
<?php
}
?>
<!--Invalid Character-->
<?php
if(isset($_GET['Invalid']))
{
$Message=$_GET['Invalid'];
$Message=" Invalid Characters ";
?>
<div class="alert alert-danger text-center"><?php echo $Message?></div>
<?php
}
?>
<!--Invalid Email-->
<?php
if(isset($_GET['VEmail']))
{
$Message=$_GET['VEmail'];
$Message=" Invalid Email ";
?>
<div class="alert alert-danger text-center"><?php echo $Message?></div>
<?php
}
?>
<!--User Invalid-->
<?php
if(isset($_GET['User']))
{
$Message=$_GET['User'];
$Message=" User Already Taken ";
?>
<div class="alert alert-danger text-center"><?php echo $Message?></div>
<?php
}
?>
<!--User Invalid-->
<?php
if(isset($_GET['Email']))
{
$Message=$_GET['Email'];
$Message=" Email Already Taken ";
?>
<div class="alert alert-danger text-center"><?php echo $Message?></div>
<?php
}
?>
<?php
if(isset($_GET['success']))
{
$Message=$_GET['success'];
$Message=" You Have Successfully Signed Up ";
?>
<div class="alert alert-success text-center"><?php echo $Message?></div>
<?php
}
?>
<div class="card-body">
<form action="includes/signup.php" method="POST">
<input type="text" name="FName" placeholder="First Name" class="form-control my-2">
<input type="text" name="LName" placeholder="Last Name" class="form-control my-2">
<input type="text" name="Email" placeholder="Email" class="form-control my-2">
<input type="text" name="UserName" placeholder="User Name" class="form-control my-2">
<input type="password" name="password" placeholder="Password " class="form-control mb-3">
<button class="btn btn-success" name="signup" class="pt-3">Signup</button>
</form>
</div>
</div>
</div>
</div>
</div>
<?php require_once('footer.php'); ?>
Then, you need to create a database and also a table to store the Application data. I mentioned code on below, you can use the same code the paste with your own created database. My Table Name is Users.
create table Users
(
user_id int primary key AUTO_INCREMENT,
user_first varchar(50),
user_last varchar(50),
user_email varchar(50),
user_uid varchar(50),
user_password varchar(300)
)
Then the next step is you need to make connection.php file. In this file, you need to make the connection between PHP and MySQLi Database.
<?php
$con=mysqli_connect('localhost','root','','usersystem');
if(!$con)
{
die('Connection Error'.mysqli_error());
}
?>
After creating Connection.php file, you need to work on PHP. So let’s get started to work on PHP to make Login System in Php with validation.
You May Also Like: User Management System in PHP
First of All, you need to make file signup.php file, in this file you need to get the data from users and enter validation, below, I mentioned codes.
<?php
require_once('connection.php');
if(isset($_POST['signup']))
{
if(empty($_POST['FName']) || empty($_POST['LName']) || empty($_POST['Email']) || empty($_POST['UserName']) || empty($_POST['password']))
{
header("location: ../signupdesign.php?empty");
}
else
{
$FName=mysqli_real_escape_string($con,$_POST['FName']);
$LName=mysqli_real_escape_string($con,$_POST['LName']);
$Email=mysqli_real_escape_string($con,$_POST['Email']);
$UserName=mysqli_real_escape_string($con,$_POST['UserName']);
$Password=mysqli_real_escape_string($con,$_POST['password']);
if(!preg_match("/^[a-zA-Z]*$/",$FName) || !preg_match("/^[a-zA-Z]*$/",$LName))
{
header("location: ../signupdesign.php?Invalid");
exit();
}
else
{
if(!filter_var($Email,FILTER_VALIDATE_EMAIL))
{
header("location: ../signupdesign.php?VEmail");
exit();
}
else
{
$query = " select * from userlogin where UserName='".$UserName."'";
$result = mysqli_query($con,$query);
if(mysqli_fetch_assoc($result))
{
header("location: ../signupdesign.php?User");
exit();
}
else
{
$query = " select * from userlogin where Email='".$Email."'";
$result = mysqli_query($con,$query);
if(mysqli_fetch_assoc($result))
{
header("location: ../signupdesign.php?Email");
exit();
}
else
{
$Hash = password_hash($Password, PASSWORD_DEFAULT);
$query = " insert into userlogin (FName,LName,Email,UserName,Password) values ('$FName', '$LName', '$Email', '$UserName','$Hash')";
$result = mysqli_query($con,$query);
header("location: ../signupdesign.php?success");
exit();
}
}
}
}
}
}
else
{
header("location: ../index.php");
exit();
}
?>
Once you have made the signup.php file, then you are able to store the value in the database with validation and also the encrypted password.
You May Also Like: Login Page in PHP with Source Code
Then the next step you need to work on login.php file, in this file you need to the login user who already registers the data. I mentioned below code, you need to copy that and paste it.
<?php
session_start();
require_once('connection.php');
if(isset($_POST['login']))
{
if(empty($_POST['UserName']) || empty($_POST['password']) )
{
header("location: ../logindesign.php?empty");
exit();
}
else
{
$UserName = mysqli_real_escape_string($con,$_POST['UserName']);
$Password = mysqli_real_escape_string($con,$_POST['password']);
$Query = " select * from userlogin where UserName='".$UserName."' or Email='".$UserName."'";
$result = mysqli_query($con,$Query);
if($row=mysqli_fetch_assoc($result))
{
$HashPass = password_verify($Password,$row['Password']);
if($HashPass==false)
{
header("location: ../logindesign.php?P_Invalid");
exit();
}
elseif($HashPass==true)
{
$_SESSION['U_D']=$row['ID'];
$_SESSION['FName']=$row['FName'];
$_SESSION['LName']=$row['LName'];
$_SESSION['Email']=$row['Email'];
$_SESSION['UserName']=$row['UserName'];
$_SESSION['Password']=$row['Password'];
header("location: ../account.php?Well");
exit();
}
}
else
{
header("location: ../logindesign.php?U_Invalid");
exit();
}
}
}
else
{
header("location: ../logindesign.php");
exit();
}
?>
Once you have complete all process, you need to do another work like logout process, user login your application and also log out.
So, You need to make logout.php file and paste below code, that’s it, guys.
<?php
if(isset($_POST['logout']))
{
session_start();
session_unset();
session_destroy();
header("location: ../index.php");
exit();
}
?>
Guys, You have successfully made Login System in PHP with Source Code. Guys, I made a video tutorial on this topic, you can watch my complete video, with the help video tutorial. You will learn step by step.
Login System in PHP with Validation
Guys, I hope you have learned something new in this video. I have mentioned each way to learn Login System in PHP with Validation. If you like it, kindly share and like the content and Share with Social Networks.
If you have any question/suggestion, comment me or email, after receiving your email. I will help you to solve your problems. Thanks For Watching and Read the Complete Article.