这两个选项对应的值即都可以在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. 【网络流24题】No. 17 运输问题 (费用流)

    [题意] W 公司有 m 个仓库和 n 个零售商店.第 i 个仓库有ai 个单位的货物:第 j 个零售商店需要b j 个单位的货物. 货物供需平衡,即SIGMA(A)=SIGMA(B). 从第 i 个 ...

  2. SPRING IN ACTION 第4版笔记-第二章-003-以Java形式注入Bean、@Bean的用法

    1. package soundsystem; import org.springframework.context.annotation.Bean; import org.springframewo ...

  3. 最新ps cs6序列号 永久免费可用

    一. 序列号 除非是从官方购买,从其它任何途径得到的序列号(包括网上流传的注册机生成的)都是不能通过联网验证的,必须使用破解补丁,或是通过修改hosts文件的方式来激活.因此,除了正版,不存在所谓的“ ...

  4. Oracle SYS_CONTEXT Function

    Version 11.1   Actions As SYS Note: USERENV is an Oracle provided namespace that describes the curre ...

  5. Codevs_1230_元素查找_(set/Hash)

    描述 http://codevs.cn/problem/1230/ ... 1230 元素查找 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond       题目 ...

  6. Hadoop RPC源码阅读-服务端Server

    Hadoop版本Hadoop2.6 RPC主要分为3个部分:(1)交互协议 (2)客户端(3)服务端 (3)服务端 RPC服务端的实例代码: public class Starter { public ...

  7. 详解Makefile 函数的语法与使用

    使用函数: 在Makefile中可以使用函数来处理变量,从而让我们的命令或是规则更为的灵活和具有智能.make所支持的函数也不算很多,不过已经足够我们的操作了.函数调用后,函数的返回值可以当做变量来使 ...

  8. Delta-wave

    Delta-wave Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  9. CMD删除Mysql 服务

    用sc.exe这个命令可以删除Windows系统服务 开始 —> 运行 —> cmd.exe,然后输入sc就可以看到了. 使用办法很简单: sc delete "服务名" ...

  10. ADB对手机进行开关机测试

    Verify issue 时,其中有条要对手机进行开关机100次,由于只有ADB环境,只能用批处理来写脚本了,代码如下: ::需配置ADB环境,开启Debug模式 ::start循环 :start s ...