这个问题以前已经以更笼统的方式提出过.我想在生产服务器上的特定页面上显示错误消息,但是我无权访问php.ini文件.在生产服务器上的特定PHP页面上启用所有错误和警告的最佳方法是什么?
This question has been asked before in a more general way. I want to display error messages on a particular page on my production server, and I do not have access to the php.ini file. What is the best way to enable all errors and warnings on a particular PHP page on your production server?
我尝试过ERROR_REPORTING(E_ALL);.
推荐答案要启用错误,必须使用 error_reporting 在触发它们的位置之前(例如,在PHP脚本的开头):
To enable errors, you must use error_reporting before the point where those are triggered (for example, at the beginning of your PHP script) :
error_reporting(E_ALL);要显示错误,您应该配置 :
And to have the error displayed, you should configure display_errors :
ini_set('display_errors', 'On');(此功能应在生产服务器上禁用,这意味着即使配置了error_reporting后,您可能也必须以这种方式启用它)
(This one should be disabled on a production server, which means you might have to enable it this way, even after having configured error_reporting)
当然,所有这些都可以封装在if块中,以确保只有您可以看到错误消息-尤其是如果您是在实时生产网站上执行此操作;例如:
Of course, all this can be encapsulated in an if block, to make sure only you can see the error messages -- especially if you are doing this on a live production website ; for instance :
if ($_SESSION['is_admin']) { error_reporting(E_ALL); ini_set('display_errors', 'On'); }为了使事情更美观,您可能还需要配置 html_errors :
And to get things a bit prettier, you might also want to configure html_errors :
ini_set('html_errors', 'On');更多推荐
PHP生产服务器
发布评论