有什么方法可以告诉 PHP 不显示错误、警告或通知消息中存在任何错误的文件的完整路径。我知道我可以禁用错误;但是,只是为了避免任何风险。
例如:我的脚本返回一个错误,显示如下:
Fatal error: Call to undefined function shell_exec1() in /home/[user]/public_html/index.php on line 1
我想显示它像
Fatal error: Call to undefined function shell_exec1() in ~/index.php on line 1
这样,显示错误消息的方式会更安全,同时不会将文件的完整路径暴露给坏人。
这可能吗?如何?
只需编写您自己的错误处理程序即可。看:http://www.php.net/manual/en/function.set-error-handler.php http://www.php.net/manual/en/function.set-error-handler.php
function myErrorHandler($errno, $errstr, $errfile, $errline) {
if (!(error_reporting() & $errno)) {
// This error code is not included in error_reporting
return;
}
switch ($errno) {
case E_USER_ERROR:
echo "<b>My ERROR</b> [$errno] $errstr<br />\n";
echo " Fatal error on line $errline in file $errfile";
echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
echo "Aborting...<br />\n";
exit(1);
break;
case E_USER_WARNING:
echo "<b>My WARNING</b> [$errno] $errstr<br />\n";
break;
case E_USER_NOTICE:
echo "<b>My NOTICE</b> [$errno] $errstr<br />\n";
break;
default:
echo "Unknown error type: [$errno] $errstr<br />\n";
break;
}
/* Don't execute PHP internal error handler */
return true;
}
set_error_handler("myErrorHandler");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)