Created
February 9, 2018 16:59
-
-
Save sectsect/849a821ad4dc9024f132de7317506429 to your computer and use it in GitHub Desktop.
Create Ramdom Tokens with PHP
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 get_token($length = 32) { | |
if ( ! isset($length) || intval($length) <= 8 ) { | |
$length = 32; | |
} | |
// PHP 7.0+ | |
if ( function_exists('random_bytes') ) { | |
return bin2hex(random_bytes($length)); | |
} | |
// PHP 5.3+ | |
if ( function_exists('openssl_random_pseudo_bytes') ) { | |
return bin2hex(openssl_random_pseudo_bytes($length)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment