get rid of more functions
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -37,6 +37,34 @@ class PhpHelper
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function randomStr
|
||||
*
|
||||
* generate a pseudo-random string of bytes
|
||||
*
|
||||
* @param int $length
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function randomStr($length)
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '7.0.0') >= 0) {
|
||||
return random_bytes($length);
|
||||
} elseif (function_exists('openssl_random_pseudo_bytes')) {
|
||||
return openssl_random_pseudo_bytes($length);
|
||||
} else {
|
||||
$pr_bits = '';
|
||||
$fp = @fopen('/dev/urandom', 'rb');
|
||||
if ($fp !== false) {
|
||||
$pr_bits .= @fread($fp, $length);
|
||||
@fclose($fp);
|
||||
} else {
|
||||
$pr_bits = substr(rand(time(), getrandmax()) . rand(time(), getrandmax()), 0, $length);
|
||||
}
|
||||
return $pr_bits;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return human readable sizes
|
||||
*
|
||||
@@ -46,8 +74,9 @@ class PhpHelper
|
||||
* maximum unit
|
||||
* @param string $system
|
||||
* 'si' for SI, 'bi' for binary prefixes
|
||||
*
|
||||
* @param string
|
||||
*
|
||||
* @param
|
||||
* string
|
||||
*/
|
||||
public static function size_readable($size, $max = null, $system = 'si', $retstring = '%01.2f %s')
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user