开发者

php.ini path inside code

开发者 https://www.devze.com 2023-02-18 20:53 出处:网络
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)

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消