PHP: How to generate a random, unique, alphanumeric string for use in a secret link?

后端 未结 28 2228
隐瞒了意图╮
隐瞒了意图╮ 2020-11-21 22:20

How would it be possible to generate a random, unique string using numbers and letters for use in a verify link? Like when you create an account on a website, and it sends y

28条回答
  •  名媛妹妹
    2020-11-21 23:19

    Use the code below to generate the random number of 11 characters or change the number as per your requirement.

    $randomNum=substr(str_shuffle("0123456789abcdefghijklmnopqrstvwxyz"), 0, 11);
    

    or we can use custom function to generate the random number

     function randomNumber($length){
         $numbers = range(0,9);
         shuffle($numbers);
         for($i = 0;$i < $length;$i++)
            $digits .= $numbers[$i];
         return $digits;
     }
    
     //generate random number
     $randomNum=randomNumber(11);
    

提交回复
热议问题