2018年02月19日


PHP の関数での環境情報取得( phpinfo の代替え )

@niftyホームページサービス(LaCoocan)では、phpinfo 関数が使用できないので、代替えの為いろいろな関数で情報を表示しています。

関数での情報取得

以下で使用している主な関数です。

ini_get
get_loaded_extensions
get_declared_classes
ini_get_all

phpversion
php_ini_loaded_file
get_include_path
get_magic_quotes_gpc


実行結果

少し見づらいですが、調査する場合や簡単な確認のとっかかりにはなると思います。

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta content="width=device-width initial-scale=1.0 minimum-scale=1.0 maximum-scale=1.0 user-scalable=no" name="viewport">
<title>phpinfo の代替え</title>
<style>
* {
	font-size: 12px;
	font-family: "ヒラギノ角ゴPro W6","Hiragino Kaku Gothic Pro W6","メイリオ",Meiryo,"MS Pゴシック",Verdana,Arial,Helvetica,sans-serif;
}

pre {
	white-space: pre-wrap;
	word-wrap: break-word;
}
</style>
</head>
<body style='width:400px;margin:auto;border:1px solid #ccc;padding:12px;'>

<pre>
<?php

	print "PHP version : " . phpversion() . "\n";

	print "php.ini : " . php_ini_loaded_file() . "\n";
	print "include_path : " . get_include_path() . "\n";
	print "get_magic_quotes : " . get_magic_quotes_gpc . "\n";

	print "variables_order : " . ini_get('variables_order') . "\n";
	print "short_open_tag : " . ini_get('short_open_tag') . "\n";
	print "display_errors : " . ini_get('display_errors') . "\n";
	print "display_startup_errors : " . ini_get('display_startup_errors') . "\n";
	print "allow_url_fopen : " . ini_get('allow_url_fopen') . "\n";
	print "allow_url_include : " . ini_get('allow_url_include') . "\n";
	print "max_execution_time : " . ini_get('max_execution_time') . "\n";
	print "post_max_size : " . ini_get('post_max_size') . "\n";
	print "track_errors : " . ini_get('track_errors') . "\n";

	print "<hr>";
	print "<b style='font-size:24;font-weight:bold'>Loaded_extensions</b>\n";

	// コンパイル/ロードされている全てのモジュールの名前を配列として返す
	$target = get_loaded_extensions();
	foreach( $target as $key => $value ) {
		print "$key => $value\n";
	}

	print "<hr>";
	print "<b style='font-size:24;font-weight:bold'>get_declared_classes</b>\n";

	// 定義済のクラスの名前を配列として返す
	$classes = get_declared_classes();
	foreach( $classes as $key => $value ) {
		print "$key => $value\n";
	}

	// $_SERVER
	print "<hr>";
	print "<b style='font-size:24;font-weight:bold'>\$_SERVER</b>\n";

	foreach( $_SERVER as $key => $value ) {
		print "$key => $value\n";
	}

	// $_ENV
	print "<hr>";
	print "<b style='font-size:24;font-weight:bold'>\$_ENV</b>\n";

	foreach( $_ENV as $key => $value ) {
		print "$key => $value\n";
	}

	// すべての設定オプションを得る
	print "<hr>";
	print "<b style='font-size:24;font-weight:bold'>ini_get_all</b>\n";
	$inis = ini_get_all();
	print_r($inis);

?>
</pre>

</body>
</html>




タグ:PHP phpinfo
【LaCoocanの最新記事】
posted by at 2018-02-19 10:06 | LaCoocan | このブログの読者になる | 更新情報をチェックする