Hướng dẫn how to see phpinfo

[PHP 4, PHP 5, PHP 7, PHP 8]

phpinfoOutputs information about PHP's configuration

Description

phpinfo[int $flags = INFO_ALL]: bool

Because every system is setup differently, phpinfo[] is commonly used to check configuration settings and for available predefined variables on a given system.

phpinfo[] is also a valuable debugging tool as it contains all EGPCS [Environment, GET, POST, Cookie, Server] data.

Parameters

flags

The output may be customized by passing one or more of the following constants bitwise values summed together in the optional flags parameter. One can also combine the respective constants or bitwise values together with the bitwise or operator.

phpinfo[] optionsName [constant]ValueDescription
INFO_GENERAL 1 The configuration line, php.ini location, build date, Web Server, System and more.
INFO_CREDITS 2 PHP Credits. See also phpcredits[].
INFO_CONFIGURATION 4 Current Local and Master values for PHP directives. See also ini_get[].
INFO_MODULES 8 Loaded modules and their respective settings. See also get_loaded_extensions[].
INFO_ENVIRONMENT 16 Environment Variable information that's also available in $_ENV.
INFO_VARIABLES 32 Shows all predefined variables from EGPCS [Environment, GET, POST, Cookie, Server].
INFO_LICENSE 64 PHP License information. See also the » license FAQ.
INFO_ALL -1 Shows all of the above.

Return Values

Returns true on success or false on failure.

Examples

Example #1 phpinfo[] Example

Notes

Note:

In versions of PHP before 5.5, parts of the information displayed are disabled when the expose_php configuration setting is set to off. This includes the PHP and Zend logos, and the credits.

Note:

phpinfo[] outputs plain text instead of HTML when using the CLI mode.

See Also

  • phpversion[] - Gets the current PHP version
  • phpcredits[] - Prints out the credits for PHP
  • ini_get[] - Gets the value of a configuration option
  • ini_set[] - Sets the value of a configuration option
  • get_loaded_extensions[] - Returns an array with the names of all modules compiled and loaded
  • Predefined Variables

Calin S.

7 years ago

After reading and trying various functions, I couldn't find one that correctly parses all the configurations, strips any left-over html tag and converts special characters into UTF8 [e.g. ' into '], so I created my own by improving on the existing ones:

function phpinfo2array[] {
    $entitiesToUtf8 = function[$input] {
        // //php.net/manual/en/function.html-entity-decode.php#104617
        return preg_replace_callback["/[&#[0-9]+;]/", function[$m] { return mb_convert_encoding[$m[1], "UTF-8", "HTML-ENTITIES"]; }, $input];
    };
    $plainText = function[$input] use [$entitiesToUtf8] {
        return trim[html_entity_decode[$entitiesToUtf8[strip_tags[$input]]]];
    };
    $titlePlainText = function[$input] use [$plainText] {
        return '# '.$plainText[$input];
    };

        ob_start[];
    phpinfo[-1];

        $phpinfo = array['phpinfo' => array[]];

    // Strip everything after the

Configuration

tag [other h2's]
    if [!preg_match['#[.*]*>\s*Configuration.*][.*?]\s*[?:[.*?]\s*]?]?]#s', ob_get_clean[], $matches, PREG_SET_ORDER]]
    foreach[
$matches as $match]
        if[
strlen[$match[1]]]
           
$phpinfo[$match[1]] = array[];
        elseif[isset[
$match[3]]]
           
$phpinfo[end[array_keys[$phpinfo]]][$match[2]] = isset[$match[4]] ? array[$match[3], $match[4]] : $match[3];
        else
           
$phpinfo[end[array_keys[$phpinfo]]][] = $match[2];
?>

Some examples of using individual values from the array:

[.*?]\s*[?:[.*?]\s*]?]?]#s', ob_get_clean[], $matches, PREG_SET_ORDER]]{
        foreach[
$matches as $match]{
        if[
strlen[$match[1]]]{
           
$phpinfo[$match[1]] = array[];
        }elseif[isset[
$match[3]]]{
       
$keys1 = array_keys[$phpinfo];
       
$phpinfo[end[$keys1]][$match[2]] = isset[$match[4]] ? array[$match[3], $match[4]] : $match[3];
        }else{
           
$keys1 = array_keys[$phpinfo];
           
$phpinfo[end[$keys1]][] = $match[2];     

                    }

                }
}

    if[! empty[

$phpinfo]]{
        foreach[
$phpinfo as $name => $section] {
            echo
"

$name

\n\n";
            foreach[
$section as $key => $val]{
                    if[
is_array[$val]]{
                    echo
"\n";
                    }elseif[
is_string[$key]]{
                    echo
"\n";
                    }else{
                    echo
"\n";
                }
            }
        }
            echo
"
$key$val[0]$val[1]
$key$val
$val
\n"
;
        }else{
    echo
"

Sorry, the phpinfo[] function is not accessable. Perhaps, it is disabledSee the documentation.

"
;
    }
}
?>
Frankly, I went thought the trouble of adding this note because the example by "jon at sitewizard dot ca"  is probably the best on the web, and thought it unfortunate that it throws errors. Hope this is useful to someone.

Mardy dot Hutchinson at gmail dot com

15 years ago

Embedding phpinfo within your page, that already has style information:

The phpinfo output is wrapped within a

, and we privatize all the style selectors that phpinfo[] creates.

Yes, we cheat on preparing the selector list.

Chủ Đề