php register form
PHP login and registration is a basic requirement for any CMS (Content management system) application. This is the starting project for any CMS. Every CMS they need registration and login system.
For security reasons need authentication system for users. There is various ways to enable authentication in your application.
This is the example both login and registration system. I have used a Mysql Database to store the registration member into the database.
The user registration will contain input to get the details from the user input.
On submitting this form, the form data are posted to PHP and stored in the database. The user password will be encrypted before storing it into the database. User inputs are validated on the client-side before posting to the PHP code. When the user logged in with the valid credentials, then the user login state is maintained in a session and he will be allowed to proceed further.
User Registration Form
This code is to show the registration form to the user. When the user submits the form with his details, After successful validation, the PHP code will read the posted form data to execute the database insert.
Create the Database Name as registration
CREATE TABLE `users` (
`id` int(10) NOT NULL,
`fullname` varchar(100) NOT NULL,
`mobileno` varchar(100) NOT NULL,
`email` varchar(100) NOT NULL,
`password` varchar(100) NOT NULL,
`date` varchar(100) NOT NULL,
`code` varchar(6) NOT NULL,
`status` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Dumping data for table `users`
--
INSERT INTO `users` (`id`, `fullname`, `mobileno`, `email`, `password`, `date`, `code`, `status`) VALUES
(1, 'Manirul Islam', '+8801885553021', 'm@gmail.com', '123456', '2020-05-22', '', 'Active'),
(3, 'sdfds', 'sddsfsd', 'y@gmail.com', '123456', '2020-05-22', '', ''),
(4, 'sdfds', 'sddsfsd', 'y@gmail.com', '123456', '2020-05-22', '', ''),
(5, 'sdfds', 'sddsfsd', 'y@gmail.com', '123456', '2020-05-22', '', '');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `users`
--
ALTER TABLE `users`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
MODIFY `id` int(10) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;
COMMIT;
First Step 1 : create Registration.php then you need create login.php,connection.php,logout.php,dashboard.php for complete this php registration form.

<!DOCTYPE html>
<html lang="en">
<head>
<title>Registration</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--===============================================================================================-->
<link rel="icon" type="image/png" href="images/icons/favicon.ico"/>
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="fonts/font-awesome-4.7.0/css/font-awesome.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="fonts/iconic/css/material-design-iconic-font.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/animate/animate.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/css-hamburgers/hamburgers.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/animsition/css/animsition.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/select2/select2.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/daterangepicker/daterangepicker.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="css/util.css">
<link rel="stylesheet" type="text/css" href="css/main.css">
<!--===============================================================================================-->
</head>
<body>
<div class="limiter">
<div class="container-login100" style="background-image: url('images/bg-01.jpg');">
<div class="wrap-login100 p-l-55 p-r-55 p-t-65 p-b-54">
<form class="login100-form action="" method="post">
<span class="login100-form-title p-b-49">
Registration Form
</span>
<h2>
<?php
if(! empty($message)) {
?>
<div class="alert alert-danger" role="alert">
<?php
echo $message;
?>
</div>
<?php } ?>
</h2>
<div class="wrap-input100 validate-input m-b-23" data-validate = "fullname is reauired">
<span class="label-input100">Full Name</span>
<input class="input100" type="text" name="fullname" placeholder="fullname">
<span class="focus-input100" data-symbol=""></span>
</div>
<div class="wrap-input100 validate-input m-b-23" data-validate = "mobileno is reauired">
<span class="label-input100">Mobile No</span>
<input class="input100" type="text" name="mobileno" placeholder="mobileno">
<span class="focus-input100" data-symbol=""></span>
</div>
<div class="wrap-input100 validate-input m-b-23" data-validate = "email is reauired">
<span class="label-input100">email address</span>
<input class="input100" type="email" name="email" placeholder="Type your email">
<span class="focus-input100" data-symbol=""></span>
</div>
<div class="wrap-input100 validate-input" data-validate="Password is required">
<span class="label-input100">Password</span>
<input class="input100" type="password" name="pass" placeholder="Type your password">
<span class="focus-input100" data-symbol=""></span>
</div>
<div class="wrap-input100 validate-input" data-validate="Password is required">
<span class="label-input100">Re-Entry Password</span>
<input class="input100" type="password" name="repass" placeholder="Type your password">
<span class="focus-input100" data-symbol=""></span>
</div>
<div class="text-right p-t-8 p-b-31">
<a href="#">
</a>
</div>
<div class="container-login100-form-btn">
<div class="wrap-login100-form-btn">
<div class="login100-form-bgbtn"></div>
<button class="login100-form-btn">
Submit
</button>
</div>
</div>
<div class="txt1 text-center p-t-54 p-b-20">
<span>
Or Sign Up Using
</span>
</div>
<div class="flex-c-m">
<a href="#" class="login100-social-item bg1">
<i class="fa fa-facebook"></i>
</a>
<a href="#" class="login100-social-item bg2">
<i class="fa fa-twitter"></i>
</a>
<a href="#" class="login100-social-item bg3">
<i class="fa fa-google"></i>
</a>
</div>
<div class="flex-col-c p-t-155">
<span class="txt1 p-b-17">
Or Sign Up Using
</span>
<a href="#" class="txt2">
Sign Up
</a>
</div>
</form>
</div>
</div>
</div>
<div id="dropDownSelect1"></div>
<!--===============================================================================================-->
<script src="vendor/jquery/jquery-3.2.1.min.js"></script>
<!--===============================================================================================-->
<script src="vendor/animsition/js/animsition.min.js"></script>
<!--===============================================================================================-->
<script src="vendor/bootstrap/js/popper.js"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<!--===============================================================================================-->
<script src="vendor/select2/select2.min.js"></script>
<!--===============================================================================================-->
<script src="vendor/daterangepicker/moment.min.js"></script>
<script src="vendor/daterangepicker/daterangepicker.js"></script>
<!--===============================================================================================-->
<script src="vendor/countdowntime/countdowntime.js"></script>
<!--===============================================================================================
<script src="js/main.js"></script>
-->
</body>
</html>
Registration Form php post insert
<?php
$error='';
$message='';
require_once('connection.php');
if(isset($_POST) & !empty($_POST))
{
$fullname = $_POST['fullname'];
$email = $_POST['email'];
$mobileno = $_POST['mobileno'];
$pass = $_POST['pass'];
$repass = $_POST['repass'];
//print_r($_POST);
if($fullname=="")
{
$message = "Insert the Full name";
}
else if($email=="")
{
$message = "insert the email";
}
else if($mobileno=="")
{
$message ="Insert the Mobile No";
}
else if($pass=="")
{
$message = "Insert the Message";
}
else if($pass == $repass)
{
$date = date('Y-m-d');
// it will start to insert data into mysql
$sql = "insert into users (fullname,mobileno,email,password,date) values ('$fullname','$mobileno','$email','$pass','$date')";
if(mysqli_query($connection,$sql))
{
$message ="Registration Successfully";
//unset($_POST);
$Verificationcode = mt_rand(100000, 999999);
$useremail = $email;
$to = "support@easyaccountingerp.com";
$emailsubject = "Registration Verification Form";
$link = "https://easyaccountingerp.com/registrationfrom/verify.php?verificationcode=$Verificationcode";
$emailmessage = "Dear User, Please verify the registration form with this link".$link.'</br> Best Regards, easyaccountingerp team';
$header = "From:support@easyaccountingerp.com \r\n";
$header.= "Cc:support@easyaccountingerp.com \r\n";
$haeder.="MIME-Version:1.0\r\n";
$retval = mail($to,$emailsubject,$emailmessage,$header);
if($retval == true)
{
$sql2 = "update users set code='$Verificationcode',status='Pending' where email='$email'";
mysqli_query($connection,$sql2);
$message = "please verify the email address before you start to login, thank you";
}
else { $message = "fail to verify the email address";}
header("Location:index.php");
}
else
{
$message = "fail to complete the registration";
}
}
else
{
$message = "Password and Re Entry Password is not match";
}
}
?>
in the registration form this is the email verification code
$Verificationcode = mt_rand(100000, 999999); $useremail = $email; $to = "support@easyaccountingerp.com"; $emailsubject = "Registration Verification Form"; $link = "https://easyaccountingerp.com/registrationfrom/verify.php?verificationcode=$Verificationcode"; $emailmessage = "Dear User, Please verify the registration form with this link".$link.' Best Regards, easyaccountingerp team'; $header = "From:support@easyaccountingerp.com \r\n"; $header.= "Cc:support@easyaccountingerp.com \r\n"; $haeder.="MIME-Version:1.0\r\n"; $retval = mail($to,$emailsubject,$emailmessage,$header); if($retval == true) { $sql2 = "update users set code='$Verificationcode',status='Pending' where email='$email'"; mysqli_query($connection,$sql2); $message = "please verify the email address before you start to login, thank you"; } else { $message = "fail to verify the email address";}

<!DOCTYPE html>
<html lang="en">
<head>
<title>Login</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/png" href="images/icons/favicon.ico"/>
<link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="fonts/font-awesome-4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="fonts/iconic/css/material-design-iconic-font.min.css">
<link rel="stylesheet" type="text/css" href="vendor/animate/animate.css">
<link rel="stylesheet" type="text/css" href="vendor/css-hamburgers/hamburgers.min.css">
<link rel="stylesheet" type="text/css" href="vendor/animsition/css/animsition.min.css">
<link rel="stylesheet" type="text/css" href="vendor/select2/select2.min.css">
<link rel="stylesheet" type="text/css" href="vendor/daterangepicker/daterangepicker.css">
<link rel="stylesheet" type="text/css" href="css/util.css">
<link rel="stylesheet" type="text/css" href="css/main.css">
</head>
<body>
<div class="limiter">
<div class="container-login100" style="background-image: url('images/bg-01.jpg');">
<div class="wrap-login100 p-l-55 p-r-55 p-t-65 p-b-54">
<form class="login100-form" action="" method="post">
<span class="login100-form-title p-b-49">
Login
</span>
<div>
<?php
if(! empty($message)) {
?>
<div class="alert alert-danger" role="alert">
<?php
echo $message;
}
?>
</div>
<div class="wrap-input100 validate-input m-b-23" data-validate = "Username is reauired">
<span class="label-input100">Email Address</span>
<input class="input100" type="text" name="username" placeholder="Type your Email Address">
<span class="focus-input100" data-symbol=""></span>
</div>
<div class="wrap-input100 validate-input" data-validate="Password is required">
<span class="label-input100">Password</span>
<input class="input100" type="password" name="pass" placeholder="Type your password">
<span class="focus-input100" data-symbol=""></span>
</div>
<div class="text-right p-t-8 p-b-31">
<a href="#">
Forgot password?
</a>
</div>
<div class="container-login100-form-btn">
<div class="wrap-login100-form-btn">
<div class="login100-form-bgbtn"></div>
<button class="login100-form-btn">
Login
</button>
</div>
</div>
<div class="txt1 text-center p-t-54 p-b-20">
<span>
Or Sign Up Using
</span>
</div>
<div class="flex-c-m">
<a href="#" class="login100-social-item bg1">
<i class="fa fa-facebook"></i>
</a>
<a href="#" class="login100-social-item bg2">
<i class="fa fa-twitter"></i>
</a>
<a href="#" class="login100-social-item bg3">
<i class="fa fa-google"></i>
</a>
</div>
<div class="flex-col-c p-t-155">
<span class="txt1 p-b-17">
Or Sign Up Using
</span>
<a href="#" class="txt2">
Sign Up
</a>
</div>
</form>
</div>
</div>
</div>
<div id="dropDownSelect1"></div>
<script src="vendor/jquery/jquery-3.2.1.min.js"></script>
<script src="vendor/animsition/js/animsition.min.js"></script>
<script src="vendor/bootstrap/js/popper.js"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="vendor/select2/select2.min.js"></script>
<script src="vendor/daterangepicker/moment.min.js"></script>
<script src="vendor/daterangepicker/daterangepicker.js"></script>
<script src="vendor/countdowntime/countdowntime.js"></script>
<script src="js/main.js"></script>
</body>
</html>
php register form login.php post method will post data to mysql server for check user is valid or not.. if user is valid then it will go to the dashboard. and username is stored into the session.
<?php
session_start();
require_once('connection.php');
if(isset($_POST) & !empty($_POST))
{
$username = $_POST['username'];
$password = $_POST['pass'];
print_r($_POST);
if($username=="" || $password=="")
{
$message = "User Name and Password is Required";
}
else if($username=="")
{
$message = "User Name is Required";
}
else if($password=="")
{
$message = "Password is Required";
}
else
{
// then it will start to check into the database
$sql = "select * from users where email='$username' and password='$password' and status='Active'";
$restul = mysqli_query($connection,$sql);
$row = mysqli_num_rows($restul);
if($row == 1)
{
$_SESSION['username'] = $username;
header("Location: dashboard.php");
}
else
{
$message = "Invalid User Name and Password";
}
}
}
?>
create new page dashboard.php. here details description is session if some one try to enter form URL it will refuse for auth.

<?php
session_start();
if(!isset($_SESSION['username']))
{
header("Location : login.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php echo "Welcome to the dashboard."; ?>
<a href="logout.php">logout</a>
</body>
</html>
Create Also logout.php page and past this code into the logout.php
<?php
session_start();
if(session_destroy())
{
header("Location: login.php");
}
?>