23 February 2022

How to generate random numbers or OTP with function in PHP?

Generate random numbers or OTP with function in PHP


function generateNumericOTP($n=6) { 
   $generator = "1357902468"; 
   $result = "";  
   for ($i = 1; $i <= $n; $i++) {  
   $result .= substr($generator, (rand()%(strlen($generator))), 1);   
   } 
   return $result;
   }  
 

generateNumericOTP(4);

No comments:

Post a Comment

How to add re-captcha v3 on all Elementor forms using coding?

 Add re-captcha v3 on all Elementor forms using coding add_action('wp_footer',function(){     ?> <script src="https://www...