Last active
December 10, 2019 20:45
-
-
Save yurimorales/af85826851266a245d6c1a457aa1db21 to your computer and use it in GitHub Desktop.
Random Token Generator - PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$generateToken = function($length = 50) { | |
$token = ""; | |
$string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | |
$maxNumbers = strlen($string); | |
$i = 0; | |
while ($i < $length) { | |
$token .= $string[ random_int(0, $maxNumbers - 1) ]; | |
$i++; | |
} | |
return $token; | |
}; | |
echo $generateToken(60) . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment