2

To get php.ini path i simply run

<?php
phpinfo();
?>

what is the way to get the php.ini path to show to the user. without showing the whole phpinfo file.

2 Answers 2

3

phpinfo(INFO_GENERAL) would be smaller

https://www.php.net/manual/en/function.phpinfo.php

Sign up to request clarification or add additional context in comments.

1 Comment

not what i wanted.. i want to use the path value for php.ini inside my script.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.