Skip to content

Instantly share code, notes, and snippets.

@tom--
Created January 4, 2016 16:28
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tom--/ff7173f9c8a3431a2f7e to your computer and use it in GitHub Desktop.
Save tom--/ff7173f9c8a3431a2f7e to your computer and use it in GitHub Desktop.
Detailed requirements checks for Yii 2.0.7's yii\base\Security::generateRandomKey()
<?php
$tests = [
"function_exists('random_bytes')",
"defined('OPENSSL_VERSION_TEXT') ? OPENSSL_VERSION_TEXT : null",
"PHP_VERSION_ID",
"function_exists('mcrypt_create_iv') ? bin2hex(mcrypt_create_iv(8, MCRYPT_DEV_URANDOM)) : null",
"DIRECTORY_SEPARATOR",
"sprintf('%o', lstat('/dev/urandom')['mode'])",
"sprintf('%o', lstat('/dev/urandom')['mode'] & 0170000)",
"bin2hex(file_get_contents('/dev/urandom', false, null, 0, 8))",
"ini_get('open_basedir')",
];
foreach ($tests as $i => $test) {
$result = eval('return ' . $test . ';');
printf("%2d %s\n %s\n\n", $i + 1, $test, var_export($result, true));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment