将Rand()生成的随机数传递给其他页面进行验证


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

我正在尝试一种方法来验证我网站上用户的电话号码。为此,我正在集成一个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-有一个输入框,用户可以输入他们在短信中收到的相同验证码。然后点击提交。他们转到第三页。请参阅以下代码:-

<?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

添加一列以设置已验证用户的标志。

EG:number_verified = 0(如果未验证编号)并且如果被验证则设置为CCD_ 2,将默认值设置为0。

添加另一列以存储随机数。我建议存储在表中,这样可以让您轻松验证!如果用户单击验证号码,则重定向页面以发送短信,同时将随机号码存储在用户表中。如果用户输入了验证码,请将其与您存储在表中的随机数进行比较,并设置number_verified = 1。希望它能帮助你!