我需要防止用户使用phpinfo()意外暴露存储在环境variables中的私有数据。 有没有办法configurationApache或php.ini禁止使用phpinfo呈现的部分?
phpinfo()显示的信息有点全部或没有。 您可以告诉phpinfo()限制要显示的信息,但是您必须相信您的用户正确调用该函数:
您可以完全使用php.ini文件中的disable_functions指令禁用该函数:
http://www.php.net/manual/en/ini.core.php#ini.disable-functions
例如:
disable_functions = phpinfo
如果你感觉冒险,你可以抓住PHP源代码,挖掘渲染环境variables的位,然后重新编译。 例如,在PHP 5.3.6中,相关的代码可以在950行左右的/ext/standard/info.c中find:
if (flag & PHP_INFO_ENVIRONMENT) { SECTION("Environment"); php_info_print_table_start(); php_info_print_table_header(2, "Variable", "Value"); for (env=environ; env!=NULL && *env !=NULL; env++) { tmp1 = estrdup(*env); if (!(tmp2=strchr(tmp1,'='))) { /* malformed entry? */ efree(tmp1); continue; } *tmp2 = 0; tmp2++; php_info_print_table_row(2, tmp1, tmp2); efree(tmp1); } php_info_print_table_end(); }