function gen_uuid($len=8) {
$hex = md5("your_random_salt_here_31415" . uniqid("", true));
$pack = pack('H*', $hex);
$uid = base64_encode($pack); // max 22 chars
$uid = ereg_replace("[^A-Za-z0-9]", "", $uid); // mixed case
//$uid = ereg_replace("[^A-Z0-9]", "", strtoupper($uid)); // uppercase only
if ($len<4) $len=4;
if ($len>128) $len=128; // prevent silliness, can remove
while (strlen($uid)<$len) $uid = $uid . gen_uuid(22); // append until length achieved
return substr($uid, 0, $len);
}
参考はこちらです
http://ja.w3support.net/index.php?db=so&id=307486