Pro-Tutr
Generate 4 digit otp - Printable Version

+- Pro-Tutr (http://protutr.com)
+-- Forum: Programming Languages (http://protutr.com/forumdisplay.php?fid=3)
+--- Forum: Php (http://protutr.com/forumdisplay.php?fid=8)
+--- Thread: Generate 4 digit otp (/showthread.php?tid=1007)



Generate 4 digit otp - Ravishankar Chavare - 03-11-2018

Code:
    function generateOTP($digits = 4){
   $i = 0; //counter
   $pin = ""; //our default pin is blank.
   while($i < $digits){
       //generate a random number between 0 and 9.
       $pin .= mt_rand(0, 9);
       $i++;
   }
   return $pin;
}


now call this generateOTP();

anywhere in php file you will get response in 4 digit if you need 6 digit otp just call 
PHP Code:
$otp=generateOTP(6);