这两个选项对应的值即都可以在php.ini文件中设置,也都可以在php代码中使用相应的函数来设置。

在php.ini文件中的设置如下:

Display_errors = On : 打开错误回显。

Display_errors = Off:关闭错误回显。

Error_reporting = ,如下:

常量

描述

1

E_ERROR

Fatal run-time errors. Errors that can not be recovered from. Execution of the script is halted

2

E_WARNING

Non-fatal run-time errors. Execution of the script is not halted

4

E_PARSE

Compile-time parse errors. Parse errors should only be generated by the parser

8

E_NOTICE

Run-time notices. The script found something that might be an error, but could also happen when running a script normally

16

E_CORE_ERROR

Fatal errors at PHP startup. This is like an E_ERROR in the PHP core

32

E_CORE_WARNING

Non-fatal errors at PHP startup. This is like an E_WARNING in the PHP core

64

E_COMPILE_ERROR

Fatal compile-time errors. This is like an E_ERROR generated by the Zend Scripting Engine

128

E_COMPILE_WARNING

Non-fatal compile-time errors. This is like an E_WARNING generated by the Zend Scripting Engine

256

E_USER_ERROR

Fatal user-generated error. This is like an E_ERROR set by the programmer using the PHP function trigger_error()

512

E_USER_WARNING

Non-fatal user-generated warning. This is like an E_WARNING set by the programmer using the PHP function trigger_error()

1024

E_USER_NOTICE

User-generated notice. This is like an E_NOTICE set by the programmer using the PHP function trigger_error()

2048

E_STRICT

Run-time notices. PHP suggest changes to your code to help interoperability and compatibility of the code

4096

E_RECOVERABLE_ERROR

Catchable fatal error. This is like an E_ERROR but can be caught by a user defined handle (see also set_error_handler())

8191

E_ALL

All errors and warnings, except level E_STRICT (E_STRICT will be part of E_ALL as of PHP 6.0)

如有多个选项值,请使用 | 隔开。

在php代码中的设置如下:

Display_errors选项的设置使用ini_set函数。

Error_reporting选项的设置使用error_reporting函数。

代码如下:

例程1:

<?php

//获取并输出php.ini里display_errors变量的值

echo ini_get('display_errors');

echo '------------1-1-1------------';

echo '<br />';

//如果display_errors = 0(即Off),则重置display_errors = 1(即On)

if (!ini_get('display_errors'))

{

  ini_set('display_errors', '1');

}

echo ini_get('display_errors');

echo '<br />';

//获取并输出php.ini里所有变量的值

$ini = ini_get_all();

print_r($ini);

?>

例程2:

<?php

//禁用错误报告

error_reporting(0);

//报告运行时错误

error_reporting(E_ERROR | E_WARNING | E_PARSE);

//报告所有错误

error_reporting(E_ALL);

?>

例程3:

<?php

//记录生产环境错误日志

error_reporting(E_ALL);

ini_set('display_errors',0);

ini_set('log_errors',1);

ini_set('error_log','E:\'.date('Y-m-d').'_phpddt.com.txt');

?>

好了,php语言的安全特性到此就讲完了。

最新文章

  1. oracle 职业学习指引
  2. 修改Mysql默认编码
  3. leetcode 236. Lowest Common Ancestor of a Binary Tree
  4. java后台异步任务执行器TaskManager
  5. [转载]QString 乱谈(3)-Qt5与中文
  6. 自己写的AES和RSA加密解密工具
  7. linux 屏幕亮度调整命令
  8. 酷狗音乐QQ显示(VC源代码)
  9. 一个原生js写的加减乘除运算
  10. 两句话帮你彻底记住gdb之eXamining memory
  11. Java IO(IO流)-2
  12. URL中“#”
  13. 关于Unity中NGUI图片精灵响应鼠标的方法
  14. random 模块
  15. [ExtJS5学习笔记]第二十节 Extjs5配合数组的push方法,动态创建并加载组件
  16. JAVA BigDecimal 用法
  17. 2PC/3PC/Paxos
  18. Python全栈开发之路 【第十五篇】:jQuery的介绍和选择器
  19. mybatis generator的maven插件,找不到properties的配置文件错误的解决
  20. InstallUtil操作WindowsService

热门文章

  1. 听同事讲 Bayesian statistics: Part 2 - Bayesian inference
  2. DZ的伪静态神马的终于OK了
  3. 在PYTHON中,用cx_Oracle连接ORACLE数据库简单示例
  4. 【BZOJ 3387】 线段树= =
  5. [topcoder]CorrectMultiplicationTwo
  6. ServiceModel Metadata Utility Tool (Svcutil.exe)
  7. [YZOJ1579]&amp;&amp;[BZOJ2450]arr
  8. C# 防止同一个账号多次登录(cache方法)
  9. Remarks on a preprint
  10. [转载]tcp可靠性的好文