PHP生产服务器-打开错误消息 [英] PHP production server - turn on error messages

查看:70
本文介绍了PHP生产服务器-打开错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题以前已经以更笼统的方式提出过.我想在生产服务器上的特定页面上显示错误消息,但是我无权访问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生产服务器-打开错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆