Last active
October 9, 2015 20:28
-
-
Save Zillionx/7a210c5d9446613b3733 to your computer and use it in GitHub Desktop.
PHP - How to make a random unique string
This file contains hidden or 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 | |
function makeUniqueString ($length=16) // $lenght - string lenght | |
{ | |
$salt = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678'; | |
$len = strlen($salt); | |
$makepass = ''; | |
mt_srand(10000000*(double)microtime()); | |
for ($i = 0; $i < $length; $i++) { | |
$makepass .= $salt[mt_rand(0,$len - 1)]; | |
} | |
return $makepass; | |
} | |
// echo | |
echo makeUniqueString(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment