wie generiere ich am besten eine zufällige ca. 40 Zeichenlange ID? Irgendwie weiß ich net, wie ich das machen soll

Johannes
Code: Alles auswählen
$zufall = rand(1, 9999999);
$id = sha1($zufall);
Code: Alles auswählen
$confirm_chars = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9');
list($usec, $sec) = explode(' ', microtime());
mt_srand($sec * $usec);
$max_chars = count($confirm_chars) - 1;
$code = '';
for ($i = 0; $i < 6; $i++)
{
$code .= $confirm_chars[mt_rand(0, $max_chars)];
}
Code: Alles auswählen
$id = md5(uniqid($user_ip));