Вы находитесь на странице: 1из 20

Experiment No.

Name: Mayuri Kandale


Roll no:30

• Codes:
1.Input_form.php:
<!DOCTYPE>
<html>
<head>
<title>Form</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<style type="text/css">
body
{
background-color: pink;
}
</style>
<script type="text/javascript">

function validate()
{
var name=document.getElementById('fnm').value;
var day=document.getElementById('day').value;
var month=document.getElementById('month').value;
var year=document.getElementById('year').value;
var gender=document.getElementById('gender').value;
var address=document.getElementById('address').value;
var city=document.getElementById('city').value;
var pin=document.getElementById('pin').value;
var mobile=document.getElementById('mobile').value;
var mail=document.getElementById('mail').value;
var pass1=document.getElementById('pass').value;
var pass2=document.getElementById('pass1').value;
var msg="";
if(name=="")
{
alert("Please enter name");
return false;
}

if(day=="-1")
{
alert("Please select day");
return false;
}

if(month=="-1")
{
alert("Please select month");
return false
}

if(year=="-1")
{
alert("Please select year");
return false;
}

if(gender=="")
{
alert("Please select gender");
return false;
}

if(address=="")
{
alert("Please enter address");
return false;
}

if(city=="")
{
alert("Please enter city");
return false;
}

if(pin=="")
{
alert("Please enter pincode");
return false;
}

if(mobile=="")
{
alert("<br>Please enter mobile number");
return false;
}

if(mail=="")
{
alert("<br>Please enter mail");
return false;
}
if(pass1==pass2)
return true;
else
{
alert("please enter matching password");
return false;
}

}
</script>
</head>
<body>

<div class="container">
<h2>Registration Form</h2>
<form enctype="multipart/form-data" action="form_db.php" method="post" onsubmit=" return
validate()" >
<div class="form-group">
<label for="first name">Enter Full Name:</label>
<input type="text" class="form-control" id="fnm" placeholder="Enter your full Name"
name="fnm" required="required">
</div>

<div class="form-group">
<label for="birth_details">Enter Your Birth details</label><br>
<label for="day">Select day: </label>
<select name="day" id="day">
<option value="-1">.....SELECT.....</option>
<?php
for($i=1;$i<31;$i++)
{
?>
<option value=<?php echo "$i"; ?>> <?php echo "$i";?></option>
<?php
}
?>
</select>

<label for="month">Select month: </label>


<select name="month" id="month">
<option value="-1">.....SELECT.....</option>
<?php

$month=['january','february','march','april','may','june','july','august','september','octomber','nov
ember','december'];

for($i=0;$i<sizeof($month);$i++)
{
?>

<option value=<?php echo "$month[$i]";?>><?php echo "$month[$i]";?></option>


<?php
}
?>
</select>

<label for="year" >Select Year</label>


<select name="year" id="year">
<option value="-1">.....SELECT.....</option>
<?php

for($i=1991;$i<=2020;$i++)
{

?>
<option value=<?php echo "$i";?>><?php echo "$i";?></option>
<?php
}

?>

</select>
</div>
<div class="form-group">
<label for="gender">Select gender</label>
<input type="radio" name="gender" id="gender" value="male">Male <input type="radio"
name="gender" value="female">Female

</div>

<div class="form-group">
<label for="address">Enter Your Address</label><br>
<textarea rows="5" cols="50" name="address" id="address">

</textarea>

</div>

<div class="form-group">
<label for="city">Enter your city: </label>
<input type="text" name="city" id="city" placeholder="Enter your city here">
</div>

<div class="form-group">
<label for="pin" >Enter Your pincode</label>
<input type="text" id="pin" name="pin" placeholder="Enter your pincode here">
</div>

<div class="form-group">
<label for="mobile" >Enter Your mobile number</label>
<input type="text" id="mobile" name="mobile" minlength="10" maxlength="10"
placeholder="Enter your mobile number here">
</div>

<div class="form-group">
<label for="mail" >Enter Your email id</label>
<input type="email" id="mail" name="mail" placeholder="Enter your email here">
</div>
<div class="form-group">
<label for="password" >Enter your password</label>
<input type="password" id="pass" name="pass" placeholder="Enter your password here">
</div>
<div class="form-group">
<label for="password" >Enter Your password again</label>
<input type="password" id="pass1" name="pass1" placeholder="Confirm your password">
</div>

<button type="submit" class="btn btn-default">Submit</button>


</form>
</div>

</body>
</html>

2. form_db.php

<?php

//print_r($_POST);

$name= explode(" ",$_POST['fnm']);


$city=trim($_POST['city']);
$day=trim($_POST['day']);
$month=trim($_POST['month']);
$year=trim($_POST['year']);
$address=trim($_POST['address']);
$pin=trim($_POST['pin']);
$mobile=trim($_POST['mobile']);
$mail_id=trim($_POST['mail']);
$pass=trim($_POST['pass']);
$gender=$_POST['gender'];
$pat="/[0-9]+/";
$msg=" ";

if(preg_match($pat, $_POST['fnm']))
{
$msg=$msg." "."<br><br>Please enter only characters in name field";
}

if(preg_match($pat,$city))
{
$msg=$msg." "."<br><br>Please enter only characters in city";
}

$str=$pin;
if(strlen($str)!=6)
{
$msg=$msg." "."<br><br>please enter 6 digit pincode";
}

$pat2="/[a-zA-Z]+/";

if(preg_match($pat2,$pin))
{
$msg=$msg. " "."<br><br> Please enter only numbers within pin";
}
$pin=$pin;
if($pin[0]=='0')
{
$msg=$msg. " "."<br><br> Pin must not start with 0";
}

if($mobile[0]!='7' && $mobile[0]!='8' && $mobile[0]!='9')


{
$msg=$msg. " "."<br><br>Mobile number should be start with 7 or 8 or 9";
}

if(strlen($pass)<4)
{
$msg=$msg. " "."<br><br> Password must contain at least 4 characters";
}
if($msg==" ")
{

$code=md5($pass);

$rev_code=strrev($code);

$four=substr($rev_code,0,4);

require 'phpmailer/PHPMailerAutoload.php';

$mail = new PHPMailer();

$mail->isSMTP();

$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;

$mail->Username = $mail_id;//sender email id


$mail->Password = 'M@yuri1998';

$mail->SMTPSecure = "ssl";
$mail->Port = 465;

$mail->Subject ='md5 code';


$mail->Body = $four.' '.'http://localhost/Exp_04_RNo_30/activation.php';
$mail->setFrom('mayurikandale2021@gmail.com','mayuri kandale persistent manager');//sender
email id

$mail->addAddress('mayukandale96@gmail.com');//receiver email id

if ($mail->send())
{
echo "<br><br>your Mail sent ".$mail->ErrorInfo;

$d=date('Y/m/d');
$status='0';
$conn=mysqli_connect('localhost','root','','wt_2');

$query="insert into register


values('".$name[0]."','".$name[1]."','".$name[2]."','".$day."','".$month."','".$year."','".$gender."','
".$address."','".$city."','".$pin."','".$mobile."','".$mail_id."','".$pass."','".$four."','".$status."','".$d.
"')";

$i=mysqli_query($conn,$query);

if($i==1)
{
echo "<br><br>Inserted successfully...................";
echo "<br><br> You have to activate your account using email information ";
}
else
{
echo "<br><br>Error in insertion..........";
include("input_form.php");
}
}
else
echo "<br><br>not sent ur mail ".$mail->ErrorInfo;

}
else
echo "<br><br><b>Errors: </b> <br>";
echo " ". $msg;

?>

3.login.php

<!DOCTYPE html>
<html>
<head>
<title>Login Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<style type="text/css">
.box
{
margin-top: 20px;
margin-left: 300px;
height: 400px;
width: 400px;
border-width: 2px;
background-color: pink;
}
</style>
<body>
<form action="login_db.php" method="post">

<div class="container">
<div class="box">
<h1>LOGIN PAGE</h1>
<div class="form-group">
<label for="email">Enter Email Id: </label><br>
<input type="text" class="form-control" name="mail" placeholder="enter mail">
</div><br><br>

<div class="form-group">
<label for="password">Enter your password: </label><br>
<input type="text" class="form-control" name="pass" placeholder="enter password">
</div><br><br>

<input type="submit" value="LOGIN">


</div>
</div>
</form>
</body>
</html>

4.login_db.php
<?php

$mail=$_POST['mail'];
$pass=$_POST['pass'];

$conn=mysqli_connect('localhost','root','','wt_2');

$query="select * from register where email='".$mail."' and password='".$pass."'";

$result=mysqli_query($conn,$query);

if(mysqli_num_rows($result)> 0)
{
while($rows=mysqli_fetch_assoc($result))
{
if($rows['status']=="1")
{
echo "<br><br>login successful";

echo "<br><br><b><center>User Details...........</center></b>";

echo "<table border='2'>";


echo" <th>first name</th>";
echo "<th>middle name</th>";
echo "<th>last name</th>";
echo "<th>day</th>";
echo "<th>month</th>";
echo "<th>year</th>";
echo "<th>gender</th>";
echo "<th>address</th>";
echo "<th>city</th>";
echo "<th>pincode</th>";
echo "<th>mobile</th>";
echo "<th>email</th>";
echo "<th>password</th>";
echo "<th>activation_code</th>";
echo "<th>status</th>";
echo "<th>registration date</th>";
echo "<tr><td>'".$rows['First_Name']."'</td>";
echo "<td>'".$rows['Middle_Name']."'</td>";
echo "<td>'".$rows['Last_Name']."'</td>";
echo "<td>'".$rows['day']."'</td>";
echo "<td>'".$rows['month']."'</td>";
echo "<td>'".$rows['year']."'</td>";
echo "<td>'".$rows['gender']."'</td>";
echo "<td>'".$rows['address']."'</td>";
echo "<td>'".$rows['city']."'</td>";
echo "<td>'".$rows['pincode']."'</td>";
echo "<td>'".$rows['mobile']."'</td>";
echo "<td>'".$rows['email']."'</td>";
echo "<td>'".$rows['password']."'</td>";
echo "<td>'".$rows['activation_code']."'</td>";
echo "<td>'".$rows['status']."'</td>";
echo "<td>'".$rows['registration_date']."'</td></tr>";
echo "</table>";

}
else
{
echo "<br><br>You have to activate your account using information sent to
your email id";

include("activation.php");
}
}
}
else
{
echo "<br><br>you need to register first";
include("input_form.php");
}

?>

5.activation.php

<!DOCTYPE html>
<html>
<head>
<title>Activation Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<style type="text/css">
.box
{
margin-top: 20px;
margin-left: 300px;
height: 400px;
width: 400px;
border-width: 2px;
background-color: cyan;
}
</style>
<body>
<div class="container">
<div class="box">
<h1>Activation Page</h1>
<form action="activation_db.php" method="post">
<div class="form-group">
<label for="Email">Enter Your email id :</label><br><br>
<input type="text" class="form-control" name="mail" placeholder="Enter email id
here">
</div>
<br><br>
<div class="form-group">
<label for="code">Enter Your activation code:</label><br><br>
<input type="text" class="form-control" name="code" placeholder="Enter your
activation code here">
</div>
<br><br>

<input type="submit" value="ACTIVATE">


</form>
</div>
</div>
</body>
</html>

6.Activation_db.php

<?php

$mail=$_POST['mail'];
$code=$_POST['code'];
$status="1";
$conn=mysqli_connect('localhost','root','','wt_2');

$query="select * from register where email='".$mail."' and activation_code='".$code."'";

$result=mysqli_query($conn,$query);

if(mysqli_num_rows($result) >0)
{
while($row=mysqli_fetch_assoc($result))
{
if($row['status']=="1")
{
echo "<br><br>Already activated user mail ....<br><br> You can login";
include("login.php");
}
else
{
$query2="update register set status='".$status."' where email='".$mail."'";

$i=mysqli_query($conn,$query2);

if($i==1)
{
echo "<br><br>Your account is activated successfully.... <br><br> You can
login";

include("login.php");
}
}
}
}
else
{
echo "<br><br>Invalid email id or activation_code";

include("activation.php");
}

?>

1. Registration Form
2. After fiiling correct details in form mail will be sent to user of activation and data will be stored
into database. Messeges of that tasks are are following.

3. Database screenshot of information stored


4. Mail inbox screenshot

5. Page appear after clicking on link in mail inbox


6. If user enter invalid details then following page appear

7. Filling valid details


8. When user fill valid details and activate the account will be activated successfully and user is
suggested to login

9. Entering valid login details


10. If user enter valid login details and he activated his account then users details will be displayed
to user

11. Entering invalid login details


12. On entering wrong login details user will be redirected to register page

13. In user again try to activate already activated account the following page will be shown to
user.

Вам также может понравиться