Skip to content

Instantly share code, notes, and snippets.

@Zillionx
Last active October 9, 2015 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zillionx/7a210c5d9446613b3733 to your computer and use it in GitHub Desktop.
Save Zillionx/7a210c5d9446613b3733 to your computer and use it in GitHub Desktop.
PHP - How to make a random unique string
<?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