Created
May 22, 2018 04:08
-
-
Save MrXploder/becf7cb1654a2957055864cd2491270e to your computer and use it in GitHub Desktop.
PHP Function to return a random alphanumeric token given the desired length
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 | |
/* | |
* @params $length (number) -> length of the random alphanumeric token | |
* @author MrXploder | |
*/ | |
function randomKey($length) { | |
$pool = array_merge(range(0,9), range('a', 'z'),range('A', 'Z')); | |
for($i=0; $i < $length; $i++) { | |
$key .= $pool[mt_rand(0, count($pool) - 1)]; | |
} | |
return $key; | |
} | |
//USAGE: | |
//echo $token = randomKey(20); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment