PHP生产服务器

编程入门 行业动态 更新时间:2024-10-21 11:47:10
本文介绍了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生产服务器

本文发布于:2023-11-26 18:21:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634671.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:服务器   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!