问题
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
回答1:
Add a column to set flag for the verified users.
EG:
number_verified = 0if the number is not verified and set tonumber_verified = 1if verified, set default to 0.
Add another column to store the random number. I recommend to store in table, this makes you to validate easily !
If the user click the verify number, then you redirect the page to send SMS, meanwhile you store the random number in the users table.
If the user entered the verification code compare it with the random number you stored in the table and set the number_verified = 1. Hope its helps you !
来源:https://stackoverflow.com/questions/34469171/pass-random-numbers-generated-from-rand-to-other-pages-for-verification