master
parent
bb42b7c6db
commit
af3da2e42a
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
function toBase62($num) {
|
||||
$chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
$result = "";
|
||||
while ($num > 0) {
|
||||
$result = $chars[$num % 62] . $result;
|
||||
$num = floor($num / 62);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function generateID() {
|
||||
$epochStart = strtotime('2020-01-01') * 1000;
|
||||
$now = round(microtime(true) * 1000) - $epochStart;
|
||||
$random = rand(0, 999); // 3-digit random number
|
||||
$id = ($now * 1000) + $random; // Combine timestamp + randomness
|
||||
return substr(str_pad(toBase62($id), 8, "0", STR_PAD_LEFT), 0, 8); // Ensure 8 chars
|
||||
}
|
||||
|
||||
echo generateID(); // Example output: "4D7hF2L3"
|
||||
?>
|
Loading…
Reference in New Issue