php 抛出异常 自定义,PHP自定义错误页面

每个人都说在活动站点中“显示启用错误”是不好的(由于某些安全问题).

现在,我们要考虑2个案例:

>该站点处于调试模式

>该站点未处于调试模式

现在,对于案例#1:

我们希望看到错误.怎么样?

ini_set('error_reporting', E_ALL);

ini_set('display_errors', 1);

没有比这更简单了.我们还可以为除Parse和Fatal之外的所有错误自定义错误处理程序.

相反,如果案例是#2:

我们希望能够停用消息:

ini_set('error_reporting', 0);

ini_set('display_errors', 0);

没关系.但是如何向用户展示一个友好的信息,例如“Hei man,有些东西真的很好.我不保证你我们正在努力修复它,因为我们非常懒惰.”

您应该再次启用错误并使用函数set_error_handler()并希望不会发生解析或致命错误.但我的第一个问题是:

Question 1: Is that possible to avoid error reporting and have a custom offline page that is loaded when something goes wrong? I mean, is it possible to have ini_set('error_reporting', 0); and ini_set('display_errors', 0); and still be able to tell PHP to load a custom Error page?

现在另一个:

Question 2: I developed a class that with the power of set_error_handler() logs errors occurred into the database. In this way I can keep track of hack attempts and other cool stuff. (And yes, i’m always sure the DB is accessible since my application shuts down if we cannot connect to the DB). Is this worth something?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值