这两个选项对应的值即都可以在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语言的安全特性到此就讲完了。

display_errors & error_reporting(php调试安全)的更多相关文章

  1. 高级php面试题(转)

    一.mysql相关知识    1. mysql优化方式            MYSQL 优化常用方法            mysql 性能优化方案      2.如何分库分表            ...

  2. 高级php面试题

    在网上看到一些高级php 的面试题目.. 最近接连面试了几家公司,有些重要问题记录一下,督促自己学习提高,同时希望给朋友们一些帮助.内容很多,一点点完善,一步步学习..有些是面试被问,有些是招聘要求, ...

  3. php常见的面试题目

    一. 基本知识点1.1 HTTP协议中几个状态码的含义:503 500 401 403 404 200 301 302...200 : 请求成功,请求的数据随之返回.301 : 永久性重定向.302 ...

  4. 高级php面试题及部分答案

    在网上看到一些高级php 的面试题目.. 闲来无事,搞了一些答案...可能不是很全面,留这以后备用吧. 一. 基本知识点1.1 HTTP协议中几个状态码的含义:503 500 401 403 404 ...

  5. PHP安全设置

    1.register_globals(全局变量注册开关) 2.magic_quotes_gpc(魔术引号开关) 3.magic_quotes_runtime(魔术引号开关) 4.magic_quote ...

  6. PHP之提升代码质量36计

    转载:https://www.binarytides.com/35-techniques-to-enhance-your-php-code/ 1.不要使用相对路径 常常会看到: require_onc ...

  7. LNMP(三)

    第二十二次课 LNMP(三) 目录 一.Nginx负载均衡 二.ssl原理 三.生成ssl密钥对 四.Nginx配置ssl 五.php-fpm的pool 六.php-fpm慢执行日志 七.open_b ...

  8. php高级工程师面试题,行不行对照看下自己的实力

    在网上看到一些高级php 的面试题目.. 最近接连面试了几家公司,有些重要问题记录一下,督促自己学习提高,同时希望给朋友们一些帮助.内容很多,一点点完善,一步步学习..有些是面试被问,有些是招聘要求, ...

  9. 高级php面试题转载

    在网上看到一些高级php 的面试题目.. 最近接连面试了几家公司,有些重要问题记录一下,督促自己学习提高,同时希望给朋友们一些帮助.内容很多,一点点完善,一步步学习..有些是面试被问,有些是招聘要求, ...

随机推荐

  1. 移动应用产品开发-android开发(二)

    这段时间实在太忙了,也没什么精力来写博客,还是没养成写博客的习惯,还是得记载下来,不然时间久了就忘记了. 早上一大早就来公司了,趁还早,拟定今天的工作内容和计划后,赶紧记载点东西. 最近做androi ...

  2. 【Uvalive 5834】 Genghis Khan the Conqueror (生成树,最优替代边)

    [题意] 一个N个点的无向图,先生成一棵最小生成树,然后给你Q次询问,每次询问都是x,y,z的形式, 表示的意思是在原图中将x,y之间的边增大(一定是变大的)到z时,此时最小生成数的值是多少.最后求Q ...

  3. 标准MD5加密算法

    标准MD5加密算法: public class Md5 { public static String getMd5(String s) { char hexDigits[] = { '0', '1', ...

  4. [wikioi]奇怪的梦境

    http://wikioi.com/problem/2833/ 拓扑排序,居然1A,哈哈. #include <cstdio> #include <iostream> #inc ...

  5. 带圆角的EditText

    转载请注明出处:http://blog.csdn.net/krislight/article 1.定义一个Drawable <?xml version="1.0" encod ...

  6. 【HDOJ】1059 Dividing

    多重背包. #include <stdio.h> #include <string.h> #define mymax(a, b) (a>b) ? a:b ]; ]; vo ...

  7. Unity3D-基本导航(NavMesh)功能实现

    1: 打开场景 2:打开Navgation窗口 菜单中: Window --> Navgation, 在Inspector旁边会出现导航界面 这个Objcet的面板是对应当前选择的物体的,旁边的 ...

  8. B. Berland Bingo

    Lately, a national version of a bingo game has become very popular in Berland. There are n players p ...

  9. 用SQL描述树

    /*40条(1层) SELECT COUNT(*) FROM t01_mwfl WHERE AZFSDM=01 AND LEVEL=1 START WITH PID=0 CONNECT BY PRIO ...

  10. 使用jenkins + python + selenium一步步搭建web自动化测试“框架”(1) - 各部件简介

    原先搭建过一个自动化测试框架,迷迷糊糊不求甚解,算是搭建了一个仅限于能用的.根本算不上框架的玩意儿. 现在回过头来好好看看究竟每一步是怎么联系起来的,是怎么运行起来的. 本次博客先说说各部件都是干什么 ...