【发布时间】:2016-03-31 20:46:20
【问题描述】:
我正在尝试一种方法来验证我网站上用户的电话号码。为此,我正在集成一个 SMS 网关。这将像这样工作:-
第 1 步/第 1 页 - 用户单击按钮以验证其电话号码。它运行脚本,使用随机数向他们的电话号码发送短信并将用户重定向到第 2 页。请参见下面的代码:-
<?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 - 有一个输入框供用户输入他们在 SMS 中收到的相同验证码。并点击提交。他们转到第 3 页。请看下面的代码:-
<?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>
谢谢 普拉奈
【问题讨论】:
-
我的问题是,在第 3 页第 3 步中,由 Rand() 生成的随机数被刷新,因此它永远不会与 SMS 上发送的内容匹配。如您所见,我已尝试使用会话变量,但似乎无法解决...请帮助!!