Email php otp authentication

Why I am not able to redirect after processing of page “PROCESS.PHP” ?

How We redirect on other page if otp is correct?

Pages : index.php
process.php
otp.php
my-form.php (after verification)

INDEX.PHP

<!DOCTYPE html>
<html>
<header>
<title>HTML Form</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<BODY>
 <form name="encryptEmail" method="post" action="process.php" onsubmit="encrypt.disabled = true; return true;" >
            <div>
            <p>
              <input type="text" name="name" placeholder="Your Full Name"></p>
             <p><input type="text" name="email" placeholder="Your E-mail Address" 						>
              </p>
              <button class="btn" type="submit" name="encrypt">Continue</button>
            </div>
</BODY>
</html>

PROCESS.PHP

<?php session_start(); $rndno=rand(100000, 999999);//OTP generate $message = urlencode("otp number.".$rndno); $to=$_POST['email']; $subject = "OTP"; $txt = "OTP: ".$rndno.""; $headers = "From: otp@postmanreply.com" ; mail($to,$subject,$txt,$headers); if(isset($_POST['encypte'])) { $_SESSION['name']=$_POST['name']; $_SESSION['email']=$_POST['email']; $_SESSION['otp']=$rndno; header( "Location: otp.php" ); } ?>

OTP.PHP

<?php
session_start();
if(isset($_POST['save']))
{
$rno=$_SESSION['otp'];
$urno=$_POST['otpvalue'];
if(!strcmp($rno,$urno))
{
$name=$_SESSION['name'];
$email=$_SESSION['email'];

echo "(header my-form.php)";
}
else{
echo "<p>Invalid OTP</p>";
}
}
//resend OTP
if(isset($_POST['resend']))
{
$message="<p class='w3-text-green'>Sucessfully send OTP to your mail.</p>";
$rno=$_SESSION['otp'];
$to=$_SESSION['email'];
$subject = "OTP";
$txt = "OTP: ".$rno."";
$headers = "From: otp@postmanreply.com" ;
mail($to,$subject,$txt,$headers);
$message="<p><b>Sucessfully resend OTP to your mail.</b></p>";
}
?><h2>ENTER OTP</h2>
<form>
<p><input type="password" placeholder="OTP" name="otpvalue"></p>
<p><button  type="submit" name="submit">Submit</button> <button name="resend">Resend</button></p>
</form>
<div><?php if(isset($message)) { echo $message; } ?>

Is it just the difference between the name of the input button here

<button class="btn" type="submit" name="encrypt">Continue</button>

compared to when you check it here

if(isset($_POST['encypte'])) {

Ohhh! Yes , There is a mistake…

IDEs like PHPStorm highlight misspellings making it easier to see these types of errors.

1 Like

The php is not working and Process.php is not redirecting . Could you please refresh the script and and provide us?

Anyone can learn to program. It takes a real engineer to learn to solve problems.

Thank you I has solve the problem and correct it. Now it is working. Thank you for you support

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.