15 lines
324 B
PHP
15 lines
324 B
PHP
<?php
|
|
|
|
namespace Vn\Web;
|
|
|
|
const DEFAULT_TOKEN_LEN = 64;
|
|
const UIDCHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
|
|
|
function uid($length) {
|
|
$bytes = bin2hex(random_bytes($length));
|
|
$r = '';
|
|
for ($i = 0; $i < $length; $i++)
|
|
$r .= UIDCHARS[hexdec(substr($bytes, $i * 2, 2)) % 64];
|
|
return $r;
|
|
}
|