Php 将Rand()生成的随机数传递给其他页面进行验证
我正试图找到一种方法来验证我网站上用户的电话号码。为此,我集成了一个短信网关。这将像这样工作:- 第1步/第1页-用户单击按钮以验证其电话号码。它运行一个脚本,该脚本使用随机号码向用户的电话号码发送短信,并将用户重新定向到第2页。请参阅下面的代码:-Php 将Rand()生成的随机数传递给其他页面进行验证,php,html,forms,random,Php,Html,Forms,Random,我正试图找到一种方法来验证我网站上用户的电话号码。为此,我集成了一个短信网关。这将像这样工作:- 第1步/第1页-用户单击按钮以验证其电话号码。它运行一个脚本,该脚本使用随机号码向用户的电话号码发送短信,并将用户重新定向到第2页。请参阅下面的代码:- <?php // Start the session session_start(); ?> <html> <head> </head> <body> <form id="sm
<?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>
<?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>
验证码:
step2/Page2-有一个输入框,用户可以输入他们在SMS中收到的相同验证码。点击提交。他们进入第三页。请参阅下面的代码:-
<?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>
<?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>
谢谢
Pranay添加一列以设置已验证用户的标志 例如:
number\u verified=0
如果该数字未经验证
如果已验证,则设置为number\u verified=1
,
将默认值设置为0
添加另一列以存储随机数。我建议存储在表中,这使您可以轻松验证!
如果用户单击验证号码,则您重定向页面以发送SMS,同时将随机号码存储在用户表中。
如果用户输入了验证码,请将其与表中存储的随机数进行比较,并设置
数字\u verified=1
。希望它能帮助你 我的问题是,在第3步第3页上,Rand()生成的随机数被刷新,因此它与SMS上发送的随机数从不匹配。我尝试过使用会话变量,正如您所看到的,但似乎无法解决。。。请帮忙!!我在数据库中添加了一个,并重试了一次,但出现了一个错误“!)解析错误:语法错误,在C:\wamp\www\L\sms2.php的第14行出现了意外的“值”(T_字符串):-?>您能发布错误代码吗,上面的代码不清楚!哪一行是第14行?`插入表名(字段名)值('value')`$sql=插入%u dbnamer(phoneverificationcode)值($phverf);?>