A better phpinfo

The phpinfo() command comes in very useful when you want to check details about your PHP install and server setup. However, there is a lot of output and you won’t need it all. Not everyone knows that you can pass parameters to the function to narrow the scope of the information displayed.

I came up with this simple method to view the results of using these parameters and make it easy to switch between them.

[sourcecode language=’php’]< ?php $options = array('CONFIGURATION', 'ENVIRONMENT', 'MODULES', 'VARIABLES', 'GENERAL', 'CREDITS', 'LICENSE', 'ALL'); $display = (empty($_GET['display']) || !in_array(strtoupper($_GET['display']), $options)) ? 'ALL' : strtoupper($_GET['display']); $navigation = array(); foreach($options as $key=>$value) {
$navigation[] = ($value != $display) ? ‘‘ . $value . ‘‘ : ‘‘ . $value . ‘‘;
}

ob_start();

switch($display) {
case ‘CONFIGURATION’:
phpinfo(INFO_CONFIGURATION);
break;

case ‘ENVIRONMENT’:
phpinfo(INFO_ENVIRONMENT);
break;

case ‘MODULES’:
phpinfo(INFO_MODULES);
break;

case ‘VARIABLES’:
phpinfo(INFO_VARIABLES);
break;

case ‘GENERAL’:
phpinfo(INFO_GENERAL);
break;

case ‘CREDITS’:
phpinfo(INFO_CREDITS);
break;

case ‘LICENSE’:
phpinfo(INFO_LICENSE);
break;

case ‘ALL’: default:
phpinfo();
break;
}

$content = ob_get_clean();

if ((‘CREDITS’ === $display) & preg_match(‘/

PHP Credits< /a>< /h1>/’, $content, $matches) & !empty($matches)) {
$content = file_get_contents(‘http://’ . $_SERVER[‘HTTP_HOST’] . $matches[1]);
}

echo str_replace(‘‘, ‘

‘ . implode(‘ | ‘, $navigation) . ‘

‘, $content);

?>[/sourcecode]

It’s also worth pointing out that the information exposed by this function can be useful to people who want to locate any weaknesses in your system so I would recommend restricting access to this file with a password, by an IP address range or only uploading the file to your webserver temporarily and removing it as soon as you’re finished with it.

Related Posts:

2 thoughts on “A better phpinfo”

  1. Great concept. I was unaware of the parameter aspect – Even though I knew it was a function. Here is some code that you might incorporate, or add to allow displaying of installed/loaded extensions.
    I have been working extensively with portable Web Servers (i.e.: Uniform Server), and was trying to incorporate XSL, Tomcat and ASP. I decided first to ‘modify’ the way my php_info() appears, allowing a listing of currently loaded extensions. Hope someone finds this useful.

    <?php

    // Get PHP INFO
    ob_start();
    phpinfo();
    $phpinfo = ob_get_contents();
    ob_end_clean();
    $phpinfo = preg_replace ('//’, ”, $phpinfo);

    //HR
    $hr = ”.PHP_EOL;

    //GET EXT INFO
    ob_start();
    echo ”.PHP_EOL;
    echo ‘‘;
    echo ”;
    echo ‘
    PHP Extensions’.PHP_EOL;
    echo ”.PHP_EOL;
    echo ”.PHP_EOL;
    echo ‘Overview’.PHP_EOL;
    echo ”.PHP_EOL;
    echo ‘Extensions’.PHP_EOL;
    $exts = array();
    foreach (get_loaded_extensions() as $ext) {
    $exts[] = $ext;
    }
    echo implode(‘, ‘, $exts).PHP_EOL;
    echo ”.PHP_EOL;
    echo ‘Details’.PHP_EOL;
    echo ”.PHP_EOL;
    foreach ($exts as $ext) {
    echo ”.$ext.”;
    $funcs = array();
    foreach (get_extension_funcs($ext) as $func) {
    $funcs[] = $func;
    }
    echo implode(‘, ‘, $funcs).PHP_EOL;
    echo ”.PHP_EOL;
    }
    echo ”.PHP_EOL;
    echo ”.PHP_EOL;
    $extinfo = ob_get_contents();
    ob_end_clean();

    //OUTPUT
    echo $phpinfo.$hr.$extinfo;

    ?>

Comments are closed.