ASSIGNMENT – 11
Q1. Write a program in PHP to create a registration form. For new
registration, it should include name, father's name, mobile number,
email and password.
Design another page for login which will have the fields email and
password. The user will enter the required details in registration page
which will be stored in an existing database. After successful
registration, the user will be redirected to the Login Page where the
email and password of existing user has to be entered. On successful
login, the user will be redirected to another page named
[Link] which will display the Name, Father's Name and
Mobile number of that existing user.
When setting the password in registration page, the password will be
stored as hashed password.
Ans:-
[Link]
<?php
$server='localhost';
$uname='root';
$pass='';
$db='bcadb';
$con=mysqli_connect($server,$uname,$pass,$db);
if ($con) {
echo "DB($db) Connection done Successfully."; }
else {
echo "Sorry!! DB($db) is not Connected!";} ?>
[Link]
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet"
href="[Link]
integrity="sha384-
Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous">
<title>Registration pages</title>
</head>
<body>
<h1>Registration Page</h1>
<form action="[Link]" method="post">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input name="email" type="email" class="form-control" id="exampleInputEmail1"
aria-describedby="emailHelp" placeholder="Enter email">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Name</label>
<input name="clName" type="text" class="form-control" id="exampleInputEmail1"
aria-describedby="emailHelp" placeholder="Enter Your Name">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Father's Name</label>
<input name="fname" type="text" class="form-control" id="exampleInputEmail1"
aria-describedby="emailHelp" placeholder="Enter your father's name">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Mobile No</label>
<input name="mobile" type="tel" class="form-control" id="exampleInputEmail1"
aria-describedby="emailHelp" placeholder="Enter Mobile Number">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Set Password</label>
<input name="pass" type="password" class="form-control"
id="exampleInputPassword1" placeholder="Password">
</div>
<input type="submit" class="btn btn-primary" value="Submit">
</form>
<!-- Optional JavaScript -->
<!-- jQuery first, then [Link], then Bootstrap JS -->
<script src="[Link] integrity="sha384-
KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"></script>
<script src="[Link]
integrity="sha384-
ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"></script>
<script src="[Link]
integrity="sha384-
JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"></script>
</body>
</html>
<?php
require "[Link]";
if($_SERVER['REQUEST_METHOD']=='POST'){
if(isset($_POST['email'])&&
isset($_POST['clName'])&&
isset($_POST['fname']) &&
isset($_POST['mobile'])&&
isset($_POST['pass']))
{
$e1=$_POST['email'];
$n1=$_POST['clName'];
$fn1=$_POST['fname'];
$m1=$_POST['mobile'];
$p1=$_POST['pass'];
// Set Encrypted Password
// $enPs1=password_hash($p1,PASSWORD_DEFAULT);
$qur1="INSERT INTO logindetail VALUES ('$e1','$n1','$fn1','$m1','$p1')";
$exe1=mysqli_query($con,$qur1);
if($exe1){
echo '
<script>
alert("Registration Successful");
[Link]="[Link]";
</script> ';}
else{
echo '
<script>
alert("Sorry!! Registration cannot Done!");
</script>
'; }}}
?>
[Link]
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet"
href="[Link]
integrity="sha384-
Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous">
<title>Login</title>
</head>
<body>
<h1>Login Page</h1>
<form action="[Link]" method="post">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input name="email" type="email" class="form-control" id="exampleInputEmail1"
aria-describedby="emailHelp" placeholder="Enter email">
<small id="emailHelp" class="form-text text-muted">We'll never share your email
with anyone else.</small>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input name="pass" type="password" class="form-control"
id="exampleInputPassword1" placeholder="Password">
</div>
<input type="submit" class="btn btn-primary" value="LogIn">
</form>
<!-- Optional JavaScript -->
<!-- jQuery first, then [Link], then Bootstrap JS -->
<script src="[Link] integrity="sha384-
KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"></script>
<script src="[Link]
integrity="sha384-
ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"></script>
<script src="[Link]
integrity="sha384-
JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"></script>
</body>
</html>
<?php
require "[Link]";
if($_SERVER['REQUEST_METHOD']=='POST'){
$email = mysqli_real_escape_string($con, $_POST['email']);
$password = mysqli_real_escape_string($con, $_POST['pass']);
$query = "SELECT * FROM logindetail WHERE email='$email' LIMIT 1";
$result = mysqli_query($con, $query);
if($result){
if(mysqli_num_rows($result) == 1){
$row = mysqli_fetch_assoc($result);
$hashedPassword = $row['pass'];
if (password_verify($password, $hashedPassword))
{
if($_SERVER['REQUEST_METHOD']=='POST'){
$ce1=$_POST['email'];
$cp1=$_POST['pass'];
$qur1="SELECT * FROM logindetail WHERE email='$ce1';";
$exc1=mysqli_query($con,$qur1);
$rowCount=mysqli_num_rows($exc1);
// Successful Login Code Starts here
if($rowCount==1){
session_start();
$rowFetch=mysqli_fetch_assoc($exc1);
$_SESSION['name']=$rowFetch['clName'];
$_SESSION['fname']=$rowFetch["fname"];
$_SESSION['monum']=$rowFetch['mobile'];
echo '
<script>
alert("Login Successful.");
[Link]="[Link]";
</script>
'; }
else{
echo '
<script>
alert("Sorry!! Login Unsuccessful!");
</script>
';} }}
else
{
echo 'Invalid password';}
}else{
echo 'Invalid Email Address';}
}else{
echo 'Something Went Wrong!';
}}
?>
[Link]
<?php
session_start();
echo "Welcome User ".$_SESSION['name'];
echo "<br> Father's Name ".$_SESSION['fname'];
echo "<br> Mobile No is ".$_SESSION['monum'];
?>