php.ini path inside code
To get php.ini path i simply run
<开发者_Python百科;?php
phpinfo();
?>
what is the way to get the php.ini path to show to the user. without showing the whole phpinfo file.
phpinfo(INFO_GENERAL)
would be smaller
http://us3.php.net/manual/en/function.phpinfo.php
If you have PHP 5.2.4 or later, you can simply use the php_ini_loaded_file() method which returns the path as a string.
If you don't have that version, here's one way.
ob_start();
phpinfo(INFO_GENERAL);
$data = ob_get_contents();
ob_end_clean();
$lines = explode("\n", $data);
foreach($lines as $line){
list($name, $value) = explode("=>", $line);
if (trim($name) == 'Loaded Configuration File') break;
}
echo $name . ' - ' . $value."\n";
That simply prints:
Loaded Configuration File - /etc/php5/cli/php.ini
Of course you could use a regex match or something fancier like that if you wanted to.
精彩评论