Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

How to check if phpinfo() exists AND is readable? WordPress

  • SOLVED

Within my code, I use the following to check if phpinfo is available:


// Try phpinfo()
/*if (function_exists('phpinfo'))
{
ob_start();
phpinfo(INFO_GENERAL);
phpinfo(INFO_ENVIRONMENT);
$phpinfo=ob_get_contents();
ob_end_clean();

$list=strip_tags($phpinfo);
$access_details['domain']=$this->scrape_phpinfo($list, 'HTTP_HOST');
$access_details['ip']=$this->scrape_phpinfo($list, 'SERVER_ADDR');
$access_details['directory']=$this->scrape_phpinfo($list, 'SCRIPT_FILENAME');
$access_details['server_hostname']=$this->scrape_phpinfo($list, 'System');
$access_details['server_ip']=@gethostbyname($access_details['server_hostname']);
}*/


I now discovered a problem on hosts, where phpinfo() exists but is not readable (displaying "Warning: phpinfo() has been disabled for security reasons in....") when trying to call the function. With the code above, the script breaks the whole site :-/

Is there another way to check if phpinfo() exists AND can be accessed too? Like
if (function_exists('phpinfo') && phpinfo == readable) ;-)

Thanks for any help!

Update 1:
according to my provider, phpinfo is blocked by Firewall, IDS and suhosin :-/

Answers (3)

2013-03-10

Dbranes answers:

You might check this one:

<?PHP
function is_disabled($function) {
$disabled_functions=explode(',',ini_get('disable_functions'));
return in_array($function, $disabled_functions);
}
?>

[[LINK href="http://www.php.net/manual/en/function.is-callable.php#79151"]]source[[/LINK]]


Robert Seyfriedsberger comments:

thats an approach, but as I see from $disabled_functions=explode(',',ini_get('disable_functions')); - phpinfo() is not in the list of disabled functions. Is there another way to check this? Like if (phpinfo('xxx') == NULL)...


Dbranes comments:

When I test this on a host with some disabled php functions:

echo ini_get('disable_functions');

I get this output:

show_source, system, shell_exec, passthru, exec, phpinfo, shell, symlink, popen, proc_open

When I modify the above code, to remove spaces:

function is_disabled($function) {
$disabled_functions=explode(',',str_replace(" ","",ini_get('disable_functions')));
return in_array($function, $disabled_functions);
}


then

echo is_disabled("phpinfo")?"is disabled":"is enabled";

gives the output:

is disabled

So if this function works for you, then you could use it in your code like this:

if(is_disabled("phpinfo")){

}else{

}

2013-03-10

Navjot Singh answers:

N/A

2013-03-10

Christianto answers:

deleted -- not working