Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
PHP: phpinfo - Manual
[go: Go Back, main page]

PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

phpversion" width="11" height="7"/> <phpcredits
Last updated: Fri, 02 May 2008

view this page in

phpinfo

(PHP 4, PHP 5)

phpinfo — いろいろな PHP 情報を出力する

説明

bool phpinfo ([ int $what ] )

現在の PHP の状態に関する、多くの情報を出力します。出力される情報には、 PHP コンパイルオプションと拡張機能、PHP のバージョン、 サーバ情報と環境(モジュールとしてコンパイルされた場合)、 PHP の環境、OS バージョン情報、パス、構成オプションのマスター およびローカルの値、HTTP ヘッダ、PHP License などがあります。

システムの設定はそれぞれ違うため、実行時設定 や 利用できる 定義済みの変数 を調べるために phpinfo() がよく使われます。

また、phpinfo() には EGPCS (Environment, GET, POST, Cookie, Server) の情報が含まれているため、デバッグツールとしても便利です。

パラメータ

what

以下にあるconstantsビット値をひとつまたは 複数個を加算して、オプションのwhat 引数に 渡すことによって出力をカスタマイズできます。 それぞれの定数やビット値をor演算子 で結んで渡すこともできます。

phpinfo() のオプション
名前(定数) 説明
INFO_GENERAL 1 configure オプション、php.ini の場所、ビルド日時、 Web サーバ、オペレーティングシステム等。
INFO_CREDITS 2 PHP クレジット。phpcredits() も参照ください。
INFO_CONFIGURATION 4 ローカルおよびマスタの、現在の PHP ディレクティブの値。 ini_get() も参照ください。
INFO_MODULES 8 ロードされているモジュールと、それぞれの設定。 get_loaded_extensions() も参照ください。
INFO_ENVIRONMENT 16 $_ENV で取得できる環境変数の情報。
INFO_VARIABLES 32 EGPCS(環境変数・GET・POST・クッキー・サーバ変数)から すべての 定義済みの変数を表示します。
INFO_LICENSE 64 PHP ライセンス情報。» ライセンス FAQ も参照ください。
INFO_ALL -1 上記のすべてを表示します。これがデフォルトです。

返り値

成功した場合に TRUE を、失敗した場合に FALSE を返します。

変更履歴

バージョン 説明
5.2.2 "Loaded Configuration File" 情報が追加されました。これまでは "Configuration File (php.ini) Path" しかありませんでした。

例1 phpinfo() の例

<?php

// すべての情報を表示します。デフォルトは INFO_ALL です。
phpinfo();

// モジュール情報だけを表示します。
// phpinfo(8) としても同じです。
phpinfo(INFO_MODULES);

?>

注意

注意: expose_phpoff の場合、一部の情報は表示されません。 これにはPHPとZendのロゴ、そしてクレジットが含まれます。

注意: CLI モードを利用している場合、phpinfo() は HTML ではなくプレーンテキストで結果を出力します。



phpversion" width="11" height="7"/> <phpcredits
Last updated: Fri, 02 May 2008
 
add a note add a note User Contributed Notes
phpinfo
Mardy dot Hutchinson at gmail dot com
10-Sep-2007 07:27
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.
Andrew dot Boag at catalyst dot net dot nz
09-Sep-2007 04:47
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 at durchholz dot org
14-Aug-2007 06:43
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
dev at cheechtech dot com
07-Jan-2007 06:35
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;
}
jb2386 at hotmail dot com
11-Oct-2006 01:29
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;
}
?>
php at SPAMMENOT dot tof2k dot com
10-Sep-2006 07:32
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 :)
code at adspeed dot com
10-Dec-2005 08:31
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)"
Helpful Harry
07-Oct-2005 12:38
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;
?>

phpversion" width="11" height="7"/> <phpcredits
Last updated: Fri, 02 May 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites