vendredi 25 décembre 2015

pass random numbers generated from Rand() to other pages for verification

I am trying to get a way to get the phone number of the users on my website verified. to do that i am integrating an SMS gateway. this will work like this :-

step 1 /page 1 - User clicks on a button to get their phone number verified. Which runs the script that sends an SMS to their phone number with a random number and re-directs the user to page 2. Please see code below:-

    <?php
// Start the session
session_start();
?>
<html>
<head>
</head>
<body>
<form id="sms2" name="sms2" method="POST" action="sms3.php">
<table width= "400">

<tr>
  <td align="right" valign="top">Verification Code:</td>
  <td align="left"><textarea name="Vefificationcode" cols="80" rows="20" id="Vefificationcode"></textarea></td>
  </tr>
  <tr>
  <td colspan="2" align="right"><input type="submit" name= "submit" value="submit"/></td>
  <p>
<?php
$_SESSION['phverf'] = rand();//set the session variable
$phverf= rand();//stores the value of rand function in phverf variable
echo "$phverf" . "\n"; // echo this just to check...when users inputs the random number received on sms
?></p>
  </tr>
  </table>
  </form>


</body>
</html>

step2/ Page2 - has an input box for the user to type in the same verification code they received in SMS. and hit submit. They go to the 3rd Page. Please see code below :-

    <?php
session_start();
?>

<html>
<head>
</head>
<body>

<?php
   echo $_SESSION['phverf'];
if(isset($_POST['submit'])){

$verificationcode= $_POST['Vefificationcode'];
echo $verificationcode;

if($_SESSION['phverf']==$verificationcode){echo"you have successfully verified your Phone Number";}
else {echo "Please type in the code sent to your phone number correctly";}
}
?>


<body>
</html>

Thanks Pranay




Aucun commentaire:

Enregistrer un commentaire