siliconid/siliconid.php

27 lines
714 B
PHP

<?php
function toBase62($num) {
$base62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
$encoded = "";
while ($num > 0) {
$encoded = $base62[$num % 62] . $encoded;
$num = floor($num / 62);
}
return $encoded;
}
function generateID() {
$epochStart = strtotime("2020-01-01") * 1000; // Milliseconds since 2020
$now = round(microtime(true) * 1000);
$timestamp = ($now - $epochStart) % 1000000000000; // Keep last 12 digits
$randomNum = rand(0, 99); // Random 2-digit number
$finalNum = ($timestamp * 100) + $randomNum;
return str_pad(toBase62($finalNum), 8, "0", STR_PAD_LEFT);
}
echo generateID(); // Example output: "A1b2C3D4"
?>