Home / PHP / PHP Create user Signup Registration page with Login script using MySQL database

PHP Create user Signup Registration page with Login script using MySQL database

How to make user authentication form with session and password encryption using PHP.

What is User SignUp form : User sign up from are used to provide facility to website user to become a part of particular website so its user can use more resources provided by website. Sign up form requires basic information about its user with minimum requirements. For example : first name, last name, male-female, username which asks for login time, password and also email. So here is the complete step by step tutorial for PHP Create user Signup Registration page with Login script using MySQL database.

What is login form : Login form display after sign up, login form basically requires username and password and any one who has the right username and password can login into any website. It will authenticate the user( Who enters the right username and password ) and allow them to use websites resources.

List of all files in this project :

  1. sign-up.php
  2. login.php
  3. dashboard.php
  4. logout.php
  5. dbconfig.php
  6. style.css

Login details:

Email = [email protected]

Password = sam

PHP Create user Signup Registration page with Login script using MySQL database.

Code for sign-up.php file.

 <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>User Registration page</title>
<link href="style/style.css" rel="stylesheet" type="text/css">
</head>

<body>

<table bgcolor="#f2f2f2" style="padding:50px" align="center" width="550px">
<form action="" method="post">
<tr><td align="center" colspan="2"> <h1>Registration Page</h1> </td></tr>
<tr>
<td> First Name : </td><td><input type="text" name="Fname"></td>
</tr>
<tr>
<td> Last Name : </td><td><input type="text" name="Lname"></td>
</tr>
<tr>
<td> Email : </td><td><input type="email" name="email"></td>
</tr>
<tr>
<td> Password : </td><td><input type="password" name="password"></td>
</tr>

<tr>
<td align="center" colspan="2"><input type="submit" name="submit"></td> </tr>
<td align="center" colspan="2"><a href="login.php"><button type="button">Click Here To Login</button></a></td></tr>

</form>
</table>

<?php
if(isset($_POST["submit"]))
{
 
 //Including dbconfig file.
include 'dbconfig.php';
 
$fname = $_POST["Fname"];
$lname = $_POST["Lname"];
$email = $_POST["email"];
$password = $_POST["password"];

$EncryptPassword = md5($password);

mysql_query("INSERT INTO signup (f_name,l_name,email,password) VALUES ('$fname','$lname','$email','$EncryptPassword')"); 

echo '<center> Sign Up form successfully submitted. </center>';

}

 ?>

</body>
</html>

Code for login.php file.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Login Page</title>
<link href="style/style.css" rel="stylesheet" type="text/css">
</head>

<body>

<table bgcolor="#f2f2f2" style="padding:50px" align="center" width="550px">
<form action="" method="post">
<tr><td align="center" colspan="2"> <h1>Login Page</h1> </td></tr>
<tr>
<td> Email : </td><td><input type="email" name="email"></td>
</tr>
<tr>
<td> Password : </td><td><input type="password" name="password"></td>
</tr>

<tr>
<td align="center" colspan="2"><input type="submit" name="submit"></td></tr>
<td align="center" colspan="2"><a href="sign-up.php"><button type="button">Click Here To SignUp</button></a></td></tr>

</form>
</table>

<?php
if(isset($_POST["submit"]))
{
 
if(count($_POST)>0) 
{
 //Including dbconfig file.
include 'dbconfig.php';
 
$email = $_POST["email"];

$password = $_POST["password"];

$EncryptPassword = md5($password);

$finalResult = mysql_query("SELECT * FROM signup WHERE email='$email' and Password = '$EncryptPassword'"); 

$confirm = mysql_fetch_array($finalResult);

if(is_array($confirm)) {
 
 session_start();
 $_SESSION['sid']=session_id();
 header("location:dashboard.php");

} else {
 

echo '<center>' . "Wrong UserName or Password..." . '</center>';

}

}
}
?>

</body>
</html>

Code for dashboard.php file.

 <?php
 session_start();
 if($_SESSION['sid']==session_id())
 {
 
 echo "<a href='logout.php'>Logout</a>";
 }
 else
 {
 header("location:login.php");
 }
?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Home Page</title>
</head>

<body>

<table border="2" cellpadding="15" cellspacing="2" width="400" align="center">
<tr><td align="center">
<h2>Welcome User</h2></td>
<tr><td align="center">
<a href='logout.php'>Logout</a>
</td></tr>
</tr>
</table>


</body>
</html>

Code for logout.php file.

 <?php

 echo "Logged out scuccessfully";
 
 session_start();
 session_destroy();
 setcookie(session_id(),time()-1);
 
 header("location:login.php");

?>

Code for dbconfig.php file.

<?php

 //This script is designed by Android-Examples.com
//Define your host here.
$hostname = "localhost";

//Define your database username here.
$username = "root";

//Define your database password here.
$password = "";

//Define your database name here.
$dbname = "test";

 $conn = mysql_connect($hostname, $username, $password);
 
 if (!$conn)
 
 {
 
 die('Could not connect: ' . mysql_error());
 
 }
 
 mysql_select_db($dbname, $conn);

 //This script is designed by Android-Examples.com

?>

Code for style.css file.

 @charset "utf-8";
/* CSS Document */

body{
 margin:0px;
 font-family:Baskerville, 'Palatino Linotype', Palatino, 'Century Schoolbook L', 'Times New Roman', serif;
 }

input[type=text], select {
 width: 100%;
 border-radius: 5px;
 margin: 7px 0;
 border: 1px solid #ccc;
 padding: 14px 18px; 
 display: inline-block;
 box-sizing: border-box;
}

input[type=email], select {
 width: 100%;
 border-radius: 5px;
 margin: 7px 0;
 border: 1px solid #ccc;
 padding: 14px 18px; 
 display: inline-block;
 box-sizing: border-box;
}

input[type=password], select {
 width: 100%;
 border-radius: 5px;
 margin: 7px 0;
 border: 1px solid #ccc;
 padding: 14px 18px; 
 display: inline-block;
 box-sizing: border-box;
}

input[type=submit]:hover {
 background-color: #00a7d1;
}

input[type=submit] {
 width: 100%;
 border: none;
 color: white;
 padding: 14px 20px;
 background-color: #01c9fb;
 margin: 8px 0;
 cursor: pointer;
 border-radius: 4px;
 
}

button[type=button] {
 width: 100%;
 border: none;
 color: white;
 padding: 14px 20px;
 background-color: #01c9fb;
 margin: 8px 0;
 cursor: pointer;
 border-radius: 4px;
 
}

button[type=button]:hover {
 background-color: #00a7d1;
}

Screenshots:

login-page

 

PHP Create user Signup Registration page with Login script using MySQL database

Click here to download PHP Create user Signup Registration page with Login script using MySQL database project with database SQL file included.

About VikasKumar

This Website is Full Free Download Metas ...................

Check Also

Use strlen function in php to get count string length

How to find string variable length in numbers in php using strlen() function. Strlen() function …