Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : PHP Options&Information : phpinfo

phpinfo

Outputs lots of PHP information (PHP 4, PHP 5)
bool phpinfo ( [int what] )

Outputs a large amount of information about the current state of PHP. This includes information about PHP compilation options and extensions, the PHP version, server information and environment (if compiled as a module), the PHP environment, OS version information, paths, master and local values of configuration options, HTTP headers, and the PHP License.

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

what

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

Table 263. phpinfo() options

Name (constant) Value Description
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. This is the default value.


Return Values

Returns TRUE on success or FALSE on failure.

Examples

Example 1855. phpinfo() Example

<?php

// Show all information, defaults to INFO_ALL
phpinfo();

// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);

?>


Notes

Note:

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.

Related Examples ( Source code ) » phpinfo



Code Examples / Notes » phpinfo

php

To obtain a phpinfo without headers (and css) :
<?
ob_start();                                                                                                        
phpinfo();                                                                                                        
$info = ob_get_contents();                                                                                        
ob_end_clean();                                                                                                    
?>
$info = preg_replace('%^.*<body>(.*)</body>.*$%ms', '$1', $info);
You can then style your tables & headings :)


jb2386

This is a slight modification to the previous code by "code at adspeed dot com" that extracts the PHP modules as an array. I used it on PHP 4.1.2 and it failed as the <h2> tags also had an align="center". So this update changes the regex for those tags:
<?php
/* parse php modules from phpinfo */
function parsePHPModules() {
ob_start();
phpinfo(INFO_MODULES);
$s = ob_get_contents();
ob_end_clean();
$s = strip_tags($s,'<h2><th><td>');
$s = preg_replace('/<th[^>]*>([^<]+)<\/th>/',"<info>\\1</info>",$s);
$s = preg_replace('/<td[^>]*>([^<]+)<\/td>/',"<info>\\1</info>",$s);
$vTmp = preg_split('/(<h2[^>]*>[^<]+<\/h2>)/',$s,-1,PREG_SPLIT_DELIM_CAPTURE);
$vModules = array();
for ($i=1;$i<count($vTmp);$i++) {
 if (preg_match('/<h2[^>]*>([^<]+)<\/h2>/',$vTmp[$i],$vMat)) {
  $vName = trim($vMat[1]);
  $vTmp2 = explode("\n",$vTmp[$i+1]);
  foreach ($vTmp2 AS $vOne) {
  $vPat = '<info>([^<]+)<\/info>';
  $vPat3 = "/$vPat\s*$vPat\s*$vPat/";
  $vPat2 = "/$vPat\s*$vPat/";
  if (preg_match($vPat3,$vOne,$vMat)) { // 3cols
    $vModules[$vName][trim($vMat[1])] = array(trim($vMat[2]),trim($vMat[3]));
  } elseif (preg_match($vPat2,$vOne,$vMat)) { // 2cols
    $vModules[$vName][trim($vMat[1])] = trim($vMat[2]);
  }
  }
 }
}
return $vModules;
}
?>


code

This function parses the phpinfo output to get details about a PHP module.
/** parse php modules from phpinfo */
function parsePHPModules() {
ob_start();
phpinfo(INFO_MODULES);
$s = ob_get_contents();
ob_end_clean();

$s = strip_tags($s,'<h2><th><td>');
$s = preg_replace('/<th[^>]*>([^<]+)<\/th>/',"<info>\\1</info>",$s);
$s = preg_replace('/<td[^>]*>([^<]+)<\/td>/',"<info>\\1</info>",$s);
$vTmp = preg_split('/(<h2>[^<]+<\/h2>)/',$s,-1,PREG_SPLIT_DELIM_CAPTURE);
$vModules = array();
for ($i=1;$i<count($vTmp);$i++) {
 if (preg_match('/<h2>([^<]+)<\/h2>/',$vTmp[$i],$vMat)) {
  $vName = trim($vMat[1]);
  $vTmp2 = explode("\n",$vTmp[$i+1]);
  foreach ($vTmp2 AS $vOne) {
   $vPat = '<info>([^<]+)<\/info>';
   $vPat3 = "/$vPat\s*$vPat\s*$vPat/";
   $vPat2 = "/$vPat\s*$vPat/";
   if (preg_match($vPat3,$vOne,$vMat)) { // 3cols
    $vModules[$vName][trim($vMat[1])] = array(trim($vMat[2]),trim($vMat[3]));
   } elseif (preg_match($vPat2,$vOne,$vMat)) { // 2cols
    $vModules[$vName][trim($vMat[1])] = trim($vMat[2]);
   }
  }
 }
}
return $vModules;
}
Sample Output:
[gd] => Array
(
 [GD Support] => enabled
 [GD Version] => bundled (2.0.28 compatible)
 [FreeType Support] => enabled
 [FreeType Linkage] => with freetype
 [FreeType Version] => 2.1.9
 [T1Lib Support] => enabled
 [GIF Read Support] => enabled
 [GIF Create Support] => enabled
 [JPG Support] => enabled
 [PNG Support] => enabled
 [WBMP Support] => enabled
 [XBM Support] => enabled
)
[date] => Array (
 [date/time support] => enabled
 [Timezone Database Version] => 2005.14
 [Timezone Database] => internal
 [Default timezone] => America/Los_Angeles
 [Directive] => Array (
    [0] => Local Value
    [1] => Master Value
 )
 [date.timezone] => Array (
    [0] => no value
    [1] => no value
 )
)
/** get a module setting */
function getModuleSetting($pModuleName,$pSetting) {
$vModules = parsePHPModules();
return $vModules[$pModuleName][$pSetting];
}
Example: getModuleSetting('gd','GD Version'); returns "bundled (2.0.28 compatible)"


dev

same as above for configuration variables
function parsePHPConfig() {
ob_start();
phpinfo(INFO_CONFIGURATION);
$s = ob_get_contents();
ob_end_clean();
$a = $mtc = array();
if (preg_match_all('/<tr><td class="e">(.*?)<\/td><td class="v">(.*?)<\/td><td class="v">(.*?)<\/td><\/tr>/',$s,$mtc,PREG_SET_ORDER)) {
foreach($mtc as $v){
if($v[2] == '<i>no value</i>') continue;
$a[$v[1]] = $v[2];
}
}
return $a;
}


andrew dot boag

One note on the above functions for cleaning up the phpinfo() HTML and throwing it into an array data structure. In order to catch all of the info tidbits the preg_match_all has to be tweaked to deal with 2 and 3 column tables.
I have changed the preg_match_all() here so that the last <td></td> is optional
function parsePHPConfig() {
   ob_start();
   phpinfo(-1);
   $s = ob_get_contents();
   ob_end_clean();
   $a = $mtc = array();
   if (preg_match_all('/<tr><td class="e">(.*?)<\/td><td class="v">(.*?)<\/td>(:?<td class="v">(.*?)<\/td>)?<\/tr>/',$s,$mtc,PREG_SET_ORDER))
       foreach($mtc as $v){
           if($v[2] == '<i>no value</i>') continue;
           $a[$v[1]] = $v[2];
       }
   }
   return $a;
}


jo

Here's a variant of "print it without headers, but include the style information":
<?php
ob_start();
phpinfo();
$info = ob_get_clean ();
$matches = array ();
$i = preg_match ('%(<style type="text/css">.*</style>).*<body>(.*)</body>%s', $info, $matches);
print $matches [1]; # Style information
print $matches [2]; # Body


mardy dot hutchinson

Embedding phpinfo within your page, that already has style information:
The phpinfo output is wrapped within a <div class='phpinfodisplay'>, and we privatize all the style selectors that phpinfo() creates.
Yes, we cheat on preparing the selector list.
<?php
ob_start();
phpinfo();
preg_match ('%<style type="text/css">(.*?)</style>.*?(<body>.*</body>)%s', ob_get_clean(), $matches);
# $matches [1]; # Style information
# $matches [2]; # Body information
echo "<div class='phpinfodisplay'><style type='text/css'>\n",
   join( "\n",
       array_map(
           create_function(
               '$i',
               'return ".phpinfodisplay " . preg_replace( "/,/", ",.phpinfodisplay ", $i );'
               ),
           preg_split( '/\n/', $matches[1] )
           )
       ),
   "</style>\n",
   $matches[2],
   "\n</div>\n";
?>
Perhaps one day the phpinfo() function will be modified to output such a safe string on its own.


helpful harry

check out this cool and fantastic colourful phpinfo()!
<?php
ob_start();
phpinfo();
$phpinfo = ob_get_contents();
ob_end_clean();
preg_match_all('/#[0-9a-fA-F]{6}/', $phpinfo, $rawmatches);
for ($i = 0; $i < count($rawmatches[0]); $i++)
  $matches[] = $rawmatches[0][$i];
$matches = array_unique($matches);
$hexvalue = '0123456789abcdef';
$j = 0;
foreach ($matches as $match)
{
  $r = '#';
  $searches[$j] = $match;
  for ($i = 0; $i < 6; $i++)
     $r .= substr($hexvalue, mt_rand(0, 15), 1);
  $replacements[$j++] = $r;
  unset($r);
}
for ($i = 0; $i < count($searches); $i++)
  $phpinfo = str_replace($searches, $replacements, $phpinfo);
echo $phpinfo;
?>


Change Language


Follow Navioo On Twitter
assert_options
assert
dl
extension_loaded
get_cfg_var
get_current_user
get_defined_constants
get_extension_funcs
get_include_path
get_included_files
get_loaded_extensions
get_magic_quotes_gpc
get_magic_quotes_runtime
get_required_files
getenv
getlastmod
getmygid
getmyinode
getmypid
getmyuid
getopt
getrusage
ini_alter
ini_get_all
ini_get
ini_restore
ini_set
main
memory_get_peak_usage
memory_get_usage
php_ini_scanned_files
php_logo_guid
php_sapi_name
php_uname
phpcredits
phpinfo
phpversion
putenv
restore_include_path
set_include_path
set_magic_quotes_runtime
set_time_limit
sys_get_temp_dir
version_compare
zend_logo_guid
zend_thread_id
zend_version
eXTReMe Tracker