php 错误报告开启详细实现

 更新时间:2016年11月25日 17:40  点击:1348

定义和用法
error_reporting() 设置 php 的报错级别并返回当前级别。

语法
error_reporting(report_level)如果参数 level 未指定,当前报错级别将被返回。下面几项是 level 可能的值

*/
//关闭所有的错误报告
error_reporting(0);
//只报告运行错误
error_reporting(e_error|e_warning|e_parse);
//报告e_notice
error_reporting(e_error|e_warning|e_parse|e_notice);
//报告所有的运行错误,除了e_notice
//这是php.ini的默认值
error_reporting(e_all ^ e_notice);
//报告所有的php错误
error_reporting(e_all);
//和error_reporting(e_all)有一样的功效,该设置也会报告所有php错误
ini_set('error_reporting', e_all);

/*

值 常量 描述
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)

*/

function unserialize_handler($errno,$errstr)     //自定义函数
{
  echo "invalid serialized value.n";       //输出指定内容
}
$serialized='foo';          //定义字符串
set_error_handler('unserialize_handler');      //设置用户自定义错误信息函数
$original=unserialize($serialized);       //从已存储的表示中创建php的值
restore_error_handler();         //恢复错误信息指针

include 'include.php教程';    //引用include.php文件

echo a();

//结果 bb
?>

include.php文件如下

<?php
//建立include.php以供其他文件调用
function a()     //定义函数a
{
  b();      //在函数a中调用函数b
}
function b()     //定义函数b
{
  c();      //在函数b中调用函数c
}
function c()     //定义函数c
{
  echo('bb');  //输出一个php backtrace
}
a();       //使用函数a
?>
其它提示:

在使用require()语句调用文件时,如果没有找到文件,require()语句会输出错误信息,并且立即终止脚本的处理.而include()语句在没有找到文件时则会输出警告,不会终止脚本的处理

<?php教程
$action = trim($_get['action']);
if($action == "sub")
{
$str = $_post['dir'];
//if(!preg_match("/^[".chr(0xa1)."-".chr(0xff)."a-za-z0-9_]+$/",$str)) //gb2312汉字字母数字下划线正则表达式
if(!preg_match("/^[x{4e00}-x{9fa5}a-za-z0-9_]+$/u",$str)) //utf-8汉字字母数字下划线正则表达式
{
      echo "<font color=red>您输入的[".$str."]含有违法字符</font>";
}
else
{
       echo "<font color=green>您输入的[".$str."]完全合法,通过!</font>";
}
}
?>

utf8_encode() 函数把 iso-8859-1 字符串编码为 utf-8。

utf8_encode(string);
*/
$str="你好,世界!";        //定义字符串
$result=utf8_decode($str);      //进行编码转换
echo $result;         //输出转换结果


//实例二

/*
utf8_decode() 函数把 utf-8 字符串解码为 iso-8859-1。

该函数把用 utf-8 方式编码的 iso-8859-1 字符串转换成单字节的 iso-8859-1 字符串。

如果成功,该函数将返回解码字符串;否则返回 false。

utf8_decode(string)

*/

$str="hello world!";        //定义字符串
$result=utf8_decode($str);      //进行编码转换
echo $result;
$result=utf8_encode($result);      //进行编码转换
echo $result;         //输出转换结果
?>

session_cache_limiter() 返回当前缓存限制的名字. 如果指定了 cache_limiter, 当前的缓存限制的名字被改为新值. 缓存限制控制着 HTTP 头发送到客户端的缓存控制. 这些确定页面内容规则的头内容可以被缓存.如果设置缓存设置为没有缓存(nocache), 将不允许任何客户端缓存. 但是公共变量可以允许缓存. 他也可以设置为私有的,这个比公共的多一点限制.

缓存显示在请求开始时被重新设置为 session_cache_limiter  的默认值.这样,你需要在每次请求时调用 session_cache_limiter() for every request (在 session_start() 调用前).

设置cache限制为'private'
*/

session_cache_limiter('private');
$cache_limiter=session_cache_limiter();
/*设置session的过期时间为30秒*/
session_cache_expire(30);
$cache_expire=session_cache_expire();
/*初始化session*/
session_start();
/*输出结果内容*/
echo "当前的session cache限制被设置为:$cache_limiter<br />";
echo "当前的session过期时间为:$cache_expire minutes";
/*
输出结果为:
the cache limiter is now set to private
the cached session pages expire after 30 minutes


*/

//实例二

/*设置caceh限制者为'private'*/
session_cache_limiter('private');
/*返回caceh限制者*/
$cache_limiter=session_cache_limiter();
echo "当前的session cache限制被设置为:$cache_limiter<br />";


//实例三

$filename="test.mpeg";
$filepath="test.mpeg";
session_start();
/*初始化session*/
session_commit();
/*输出请求的文件*/
header("content-type: audio/x-mpeg");  //或者其他类型的文件
header("content-disposition:attachment;filename=".$filename);
header("content-length:".$filesize);
header("content-transfer-encoding:binarynn");
header("pragma:no-cache");
header("expires:0");
$file_contents=file_get_contents($filepath);
print($file_contents

);

[!--infotagslink--]

相关文章

  • Ecshop提示Only variables should be passed by reference in错误

    在安装好ecshop软件之后我们打开首页时提示Only variables should be passed by reference in错误了,碰到这个问题是什么原因呢?下面我们就一起来看看解决办法吧。...2016-11-25
  • 409错误是什么 http 409错误怎么解决

    409错误是什么?http 409错误怎么解决呢?不少站长在遇到这个错误代码之后都一筹莫展,本次一聚教程网为大家带来了详细的说明,快来看看吧。 409错误是什么: HTTP 40...2017-01-22
  • 414错误是什么 414错误怎么解决

    414错误是HTTP协议状态码中的一种,很多都还不知道414错误是什么,以及不知道怎么解决414错误,那么就来看看小编带来的介绍吧。 414错误是什么: HTTP 414错误,(Requ...2017-01-22
  • http 405错误是什么 http 405错误怎么解决

    http 405错误是什么?http 405错误怎么解决?相信很多站长都在找这两个问题的答案,本次小编为大家带来了详细的教程,快来看看吧。 405错误是什么: HTTP 405错误是H...2017-01-22
  • 401错误码代表什么 401错误解决办法

    401是HTTP状态码的一种,属于“请示错误”,表示请求可能出错,已妨碍了服务器对请求的处理。具体的401错误是指:未授权,请求要求进行身份验证。登录后,服务器可能会返回对页面...2017-01-22
  • http 402错误是什么 http 402简介

    http 402错误是什么?402错误较为少见,一般不轻易出现,下面小编就来告诉大家402错误是什么吧。 HTTP 402错误是HTTP状态码的一种,表示“要求付费”; 所求的...2017-01-22
  • 411错误是什么 411错误怎么解决

    411错误是HTTP协议状态码的一种,很多人都还不知道411错误是什么,本次一聚教程网将为大家进行解答,并且告诉大家411错误怎么解决。 411错误是什么: HTTP 411错误,(Lengt...2017-01-22
  • apache网站提示503错误解决办法

    Apache status 503 的原因大致有如下几种情况 : 1、 CPU 负载过高,服务器响应不过来,返回503 2、 系统连接数超限,超过MaxVhostClients的上限,返回503 3、 单IP连接数超限,超过M...2016-01-28
  • 404错误是什么 404错误怎么解决

    403错误是网站访问过程中,常见的错误提示。资源不可用,服务器理解客户的请求,但拒绝处理它。通常由于服务器上文件或目录的权限设置导致,比如IIS或者apache设置了访问权限...2017-01-22
  • 403错误是什么 403错误怎么解决

    403错误是HTTP状态码的一种,属于“请示错误”,表示服务器拒绝请求。如果在搜索引擎尝试抓取您网站上的有效网页时显示此状态代码,那么,这可能是您的服务器或主机拒绝搜索...2017-01-22
  • 412错误是什么 412错误怎么解决

    412错误是什么?412错误怎么解决?本次一聚教程网将为大家带来详细的介绍,帮助大家全面了解412错误的意思以及解决412错误的方法。 412错误是什么: HTTP 412错误,(Precond...2017-01-22
  • HTTP 408错误是什么 HTTP 408错误解决方法

    相信很多站长都遇到过这样一个问题,访问页面时出现408错误,下面一聚教程网将为大家介绍408错误出现的原因以及408错误的解决办法。 HTTP 408错误出现原因: HTT...2017-01-22
  • 406错误是什么 406错误怎么解决

    HTTP 406错误是HTTP协议状态码的一种,表示无法使用请求的内容特性来响应请求的网页。一般是指客户端浏览器不接受所请求页面的 MIME 类型。 而MIME类型是在把输出...2017-01-22
  • 407错误是什么 407错误怎么解决

    407错误是什么?407错误怎么解决?不少站长都遇到过407错误,下面小编将告诉大家如何处理407错误。 407错误是什么: HTTP 407错误是HTTP协议状态码的一种,表示需要代...2017-01-22
  • 410错误是什么 http 410错误怎么解决

    410错误是HTTP协议状态码的一种,本次一聚教程网将为大家详细介绍HTTP 410错误是什么,以及410错误的解决办法。 410错误是什么: HTTP 410错误是HTTP协议状态码的...2017-01-22
  • HTTP 400错误是什么 HTTP 400错误怎么解决

    每当遇到http错误代码为400,代表客户端发起的请求不符合服务器对请求的某些限制,或者请求本身存在一定的错误,那么HTTP 400错误怎么解决呢?请看下文介绍。 目前400错...2017-01-22
  • PHP Fatal error: Cannot use object of type stdClass as array in错误

    下面一起来看看在php开发中碰到PHP Fatal error: Cannot use object of type stdClass as array in错误问题的解决办法吧。 普通的数组出现如下错误 代码...2016-11-25
  • PHP Curl出现403错误的解决办法

    自己用的小PHP应用,使用curl抓网页下来处理,为了穿墙方便,使用Privoxy作为代理,便于选择哪些网站使用proxy、哪些不用。但今天却遇到了奇怪的问题,访问google baidu这些网站居然都返回403错误,而访问其他的一些网站没事,如果...2014-05-31
  • C#新手常犯的错误汇总

    这篇文章主要介绍了C#新手常犯的错误汇总,对于经验丰富的C#程序员同样具有很好的参考借鉴价值,需要的朋友可以参考下...2020-06-25
  • MySQL ERROR 2013 (HY000)错误解决方法

    当通过 TCP/IP 连接 MySQL 远程主机时,出现 ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 104 。如果是在linux shell命令行中直接打 mysql 命令,...2015-03-15