首页 > 编程技术 > php

php 错误报告开启详细实现

发布时间:2016-11-25 17:40

定义和用法
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--]

您可能感兴趣的文章: