本文整理汇总了PHP中XenForo_Application::_randomData方法的典型用法代码示例。如果您正苦于以下问题:PHP XenForo_Application::_randomData方法的具体用法?PHP XenForo_Application::_randomData怎么用?PHP XenForo_Application::_randomData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XenForo_Application
的用法示例。
在下文中一共展示了XenForo_Application::_randomData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateRandomString
/**
* Generates a psuedo-random string of the specified length.
*
* @param integer $length
*
* @return string
*/
public static function generateRandomString($length)
{
while (strlen(self::$_randomData) < $length) {
// openssl_random_pseudo_bytes is *ridiculously* slow on windows
if (function_exists('openssl_random_pseudo_bytes') && substr(PHP_OS, 0, 3) != 'WIN') {
self::$_randomData .= bin2hex(openssl_random_pseudo_bytes(max($length, 1024) / 2));
} else {
self::$_randomData .= md5(uniqid(mt_rand(), true));
}
}
$return = substr(self::$_randomData, 0, $length);
self::$_randomData = substr(self::$_randomData, $length);
return $return;
}
示例2: generateRandomString
/**
* Generates a psuedo-random string of the specified length.
*
* @param integer $length
* @param boolean $raw If true, raw binary is returned, otherwise modified base64
*
* @return string
*/
public static function generateRandomString($length, $raw = false)
{
$mixInternal = false;
while (strlen(self::$_randomData) < $length) {
if (function_exists('openssl_random_pseudo_bytes') && (substr(PHP_OS, 0, 3) != 'WIN' || version_compare(phpversion(), '5.3.4', '>='))) {
self::$_randomData .= openssl_random_pseudo_bytes($length);
$mixInternal = true;
} else {
if (function_exists('mcrypt_create_iv') && version_compare(phpversion(), '5.3.0', '>=')) {
self::$_randomData .= mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
$mixInternal = true;
} else {
if (substr(PHP_OS, 0, 3) != 'WIN' && @file_exists('/dev/urandom') && @is_readable('/dev/urandom') && ($fp = @fopen('/dev/urandom', 'r'))) {
if (function_exists('stream_set_read_buffer')) {
stream_set_read_buffer($fp, 0);
}
self::$_randomData .= fread($fp, $length);
fclose($fp);
$mixInternal = true;
} else {
self::$_randomData .= self::generateInternalRandomValue();
}
}
}
}
$return = substr(self::$_randomData, 0, $length);
self::$_randomData = substr(self::$_randomData, $length);
// have seen situations where duplicates may be read(!?!) so mix
// in another source
if ($mixInternal) {
$final = '';
foreach (str_split($return, 16) as $i => $part) {
$internal = uniqid(mt_rand());
if ($i % 2 == 0) {
$final .= md5($part . $internal, true);
} else {
$final .= md5($internal . $part, true);
}
}
$return = substr($final, 0, $length);
}
if ($raw) {
return $return;
}
// modified base64 to be more URL safe (roughly in rfc4648)
return substr(strtr(base64_encode($return), array('=' => '', "\r" => '', "\n" => '', '+' => '-', '/' => '_')), 0, $length);
}