Skip to content

Instantly share code, notes, and snippets.

@celmaun
Last active August 29, 2015 13:57
Show Gist options
  • Save celmaun/9700965 to your computer and use it in GitHub Desktop.
Save celmaun/9700965 to your computer and use it in GitHub Desktop.
function create_guid() {
$random_bytes = '';
if (function_exists('mcrypt_create_iv')) {
$random_bytes .= @mcrypt_create_iv(100, MCRYPT_DEV_URANDOM);
}
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { // Unix
if ($fp = @fopen('/dev/urandom','rb')) {
$random_bytes .= @fread($fp, 100);
@fclose($fp);
}
// (openssl_random_pseudo_bytes is very slow on Windows)
if (function_exists('openssl_random_pseudo_bytes')) $random_bytes .= openssl_random_pseudo_bytes(100);
}
$random_bytes .= mt_rand() . uniqid(mt_rand(), true) . microtime() . lcg_value() . getmypid() . memory_get_usage() . serialize($_SERVER);
return hash('sha256', $random_bytes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment