generowało się unikatowe user id
Tak na szybko:
[ uniqid ] [ microtime ] [ ini_set ] [ random_bytes ] [ openssl_random_pseudo_bytes ]
[ crypt() ] [ random_int ]
<?php
$user_id = str_replace('.', '', uniqid('user_', true));
echo $user_id;
?>
<?php
$m = microtime(true);
$user_id = str_replace('0.', '', floor($m).($m - floor($m)));
echo $user_id;
?>
<?php
$user_id = ltrim((microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]), '0.');
echo $user_id;
?>
<?php
ini_set("precision", 18);
$user_id = 'id_'.(microtime(true)/0.00000001);
echo $user_id;
?>
You should instead opt for: uniqidReal()
<!DOCTYPE html>
<html>
<body>
<pre>
<?php
function uniqidReal($lenght = 13) {
if (function_exists("random_bytes")) {
$bytes = random_bytes(ceil($lenght / 2));
} elseif (function_exists("openssl_random_pseudo_bytes")) {
$bytes = openssl_random_pseudo_bytes(ceil($lenght / 2));
} else {
throw new Exception("no cryptographically secure random function available");
}
return substr(bin2hex($bytes), 0, $lenght);
}
for($i=0; $i<=5; ++$i) {
$uniqid_real = uniqidReal();
echo uniqid(), "\t", $uniqid_real, PHP_EOL;
}
?>
</pre>
</body>
</html>
Wszystko razem, co wyżej: 
<!DOCTYPE html>
<html>
<head>
<style>
pre {
font: 1em/1.6em monospace;
}
</style>
</head>
<body>
<pre>
<?php
$m = microtime(true);
$user_id = str_replace('0.', '', floor($m).($m-floor($m)));
echo '<mark> microtime(): </mark> ', $user_id, PHP_EOL;
$user_id = str_replace('.', '', uniqid('user_', true));
echo '<mark> uniqid(): </mark> ', $user_id, PHP_EOL;
$user_id = ltrim(($m - $_SERVER["REQUEST_TIME_FLOAT"]), '0.');
echo '<mark> $_SERVER["REQUEST_TIME_FLOAT"]: </mark> ', $user_id, PHP_EOL;
ini_set("precision", 18);
$user_id = 'id_'.($m/0.00000001);
echo '<mark> ini_set("precision", 18): </mark> ',$user_id, PHP_EOL, PHP_EOL;
function uniqidReal($lenght = 13) {
if (function_exists("random_bytes")) {
$bytes = random_bytes(ceil($lenght / 2));
} elseif (function_exists("openssl_random_pseudo_bytes")) {
$bytes = openssl_random_pseudo_bytes(ceil($lenght / 2));
} else {
throw new Exception("no cryptographically secure random function available");
}
return substr(bin2hex($bytes), 0, $lenght);
}
echo '<mark>uniqid()</mark>', "\t\t", '<mark>uniqidReal()</mark>', PHP_EOL;
for($i=0; $i<=5; ++$i) {
$uniqid_real = uniqidReal();
echo uniqid(), "\t\t", $uniqid_real, PHP_EOL;
}
?>
</pre>
</body>
</html>
