Generating confirmation code for an email confirmation

前端 未结 5 883
感情败类
感情败类 2020-12-02 05:29

Using PHP, what are some ways to generate a random confirmation code that can be stored in a DB and be used for email confirmation? I can\'t for the life of me think of a wa

5条回答
  •  执念已碎
    2020-12-02 06:07

      private  function generateCodeSecurity()
      {
        list($usec, $sec) = explode(" ", microtime());
        $micro = usec + $sec;
    
        $hoy = date("Y-m-d");  
        $str = str_replace('-','',$hoy); 
    
        return  rand($str,  $micro);
    
      }
    

    With this little code, you can generate a random number, with a range of 7 to 11 numbers.

    Using php functions:

    Rand ();
    Microtime ()
    
    
    
    $hoy = date("Y-m-d");  
    $str = str_replace('-','',$hoy); 
    
    echo $str; 
    result date: 20170217
    
    
    
     list($usec, $sec) = explode(" ", microtime());
     $micro = usec + $sec;
    
    
    echo $micro;
    result  micro varaible: 1487340849
    

    Passing parameters in this function:rand ();

     rand($str,  $micro);
    

    and return;

    example:

     list($usec, $sec) = explode(" ", microtime());
        $micro = usec + $sec;
    
        $hoy = date("Y-m-d");  
        $str = str_replace('-','',$hoy); 
    
       $finalresult = rand($str,  $micro);
    
    echo $finalresult; 
    

    result: 1297793555

    I think it is difficult to repeat this number, for the reason it will never be the same day, nor the same hour, nor the same milliseconds of time.

提交回复
热议问题