Last active
November 21, 2019 12:48
-
-
Save amirkhiz/6308cbbe7ad8c87b6509690515220372 to your computer and use it in GitHub Desktop.
Generate unique Alphanumeric code 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 | |
// Reference https://codebriefly.com/unique-alphanumeric-string-php/ | |
function unique_code($limit) | |
{ | |
return substr(base_convert(sha1(uniqid(mt_rand())), 16, 36), 0, $limit); | |
} | |
echo unique_code(8); | |
// Output looks : s5s108df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment