A super easy PHP Framework for web development!
https://github.com/exacti/phacil-framework
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
490 B
17 lines
490 B
<?php
|
|
|
|
function token($length = 32) {
|
|
if(!isset($length) || intval($length) <= 8 ){
|
|
$length = 32;
|
|
}
|
|
if (function_exists('random_bytes')) {
|
|
$token = bin2hex(random_bytes($length));
|
|
}
|
|
if (function_exists('mcrypt_create_iv') && phpversion() < '7.1') {
|
|
$token = bin2hex(mcrypt_create_iv($length, MCRYPT_DEV_URANDOM));
|
|
}
|
|
if (function_exists('openssl_random_pseudo_bytes')) {
|
|
$token = bin2hex(openssl_random_pseudo_bytes($length));
|
|
}
|
|
return substr($token, -$length, $length);
|
|
}
|
|
|