Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php自定义错误处理_Php_Error Handling - Fatal编程技术网

php自定义错误处理

php自定义错误处理,php,error-handling,Php,Error Handling,我有个问题要问你 在我的站点上,我有以下错误报告级别 // PHP errors that will be reported when the script is run. error_reporting(0); 问题是,当会话超时时,我会看到一个空白页面,用户必须再次键入地址才能转到主页并登录 有没有一种方法可以嵌入到上述代码的链接,这样当会话超时时,它会回显到主页的链接 我试过了 // PHP errors that will be reported when the script is

我有个问题要问你

在我的站点上,我有以下错误报告级别

// PHP errors that will be reported when the script is run.
error_reporting(0);
问题是,当会话超时时,我会看到一个空白页面,用户必须再次键入地址才能转到主页并登录

有没有一种方法可以嵌入到上述代码的链接,这样当会话超时时,它会回显到主页的链接

我试过了

// PHP errors that will be reported when the script is run.
error_reporting(0);
echo ("index.php");
没有运气, 有什么想法吗


谢谢。:)

如果用户的会话已过期,会话检查代码应执行HTTP重定向到登录页面

session_start();

// Check if User is logged in
if (!isset($_SESSION['current_user'])) {
    header("Location: http://example.com/login");
    exit;
}

// Code to run when a User is logged in

....
哦,天哪

> error_reporting(0);
应始终报告错误,但应将生产系统的显示错误设置为“关闭”

> so when the session times out...
会话超时不会抛出错误。要么是您的代码触发了错误,要么是您正在谈论请求超时。(如果您没有禁用错误报告,您可能可以自己解决这个问题)


Stephen提供了一个如何检查无效会话状态的示例,但是从您自己的代码中抛出错误并不一定是坏事,只要您提供捕获错误的机制-请参见。

检查您存储在会话中的数据,如果未设置,请使用header()发送“位置”标题返回到浏览器。