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

心已入冬 提交于 2020-01-07 03:05:29

问题


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 = 0 if the number is not verified and set to number_verified = 1 if 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!