source: branches/version-2_4-dev/html/handle_error.php @ 18500

Revision 18500, 3.2 KB checked in by nanasess, 14 years ago (diff)

エラーハンドリングの変更(#573, #567)

  • data/require_base.php で行っていた処理を data/app_initial.php, data/require_classes.php に分散
  • アプリケーション初期化時に, DBアクセスを伴わない data/require_safe.php を追加
  • システムエラー表示用の html/error.php を追加
  • エラーハンドリング処理を行う html/handle_error.php を追加
  • data/class/SC_DbConn.php でのエラーハンドリングを trigger_error に変更
  • エラーハンドリングの変更に伴い, html/require.php, html/mobile/require.php を修正
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Revision Date
  • Property svn:mime-type set to text/x-httpd-php
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24// エラー捕捉用の出力バッファリング
25ob_start('_fatal_error_handler');
26
27// エラー画面を表示させるためのエラーハンドラ
28set_error_handler('handle_error');
29
30/**
31 * エラーを捕捉するための関数.
32 *
33 * PHP4 では, try/catch が使用できず, かつ set_error_handler で Fatal Error は
34 * 捕捉できないため, ob_start にこの関数を定義し, Fatal Error が発生した場合
35 * に出力される HTML 出力を捕捉する.
36 * この関数が実行され, エラーが捕捉されると, エラーページへリダイレクトする.
37 *
38 * @param string $buffer 出力バッファリングの内容
39 * @return string|void エラーが捕捉された場合は, エラーページへリダイレクトする;
40 *                     エラーが捕捉されない場合は, 出力バッファリングの内容を返す
41 */
42function &_fatal_error_handler(&$buffer) {
43    if (preg_match('/<b>(Fatal) error<\/b>: +(.+) in <b>(.+)<\/b> on line <b>(\d+)<\/b><br \/>/i', $buffer, $matches)) {
44        header("Location: " . SITE_URL . "error.php");
45        exit;
46    }
47    return $buffer;
48}
49
50/**
51 * エラー画面を表示させるための関数.
52 *
53 * この関数は, set_error_handler() 関数に登録するための関数である.
54 * trigger_error にて E_USER_ERROR が生成されると, ob_end_clean() 関数によって
55 * 出力バッファリングが無効にされ, エラーログを出力した後, エラーページへ
56 * リダイレクトする.
57 *
58 * E_USER_ERROR 以外のエラーが生成された場合, この関数は true を返す.
59 *
60 * @param integer $errno エラーコード
61 * @param string $errstr エラーメッセージ
62 * @param string $errfile エラーが発生したファイル名
63 * @param integer $errline エラーが発生した行番号
64 * @return void|boolean E_USER_ERROR が発生した場合は, エラーページへリダイレクト;
65 *                      E_USER_ERROR 以外の場合は true
66 */
67function handle_error($errno, $errstr, $errfile, $errline) {
68    switch ($errno) {
69    case E_USER_ERROR:
70        ob_end_clean();
71        error_log("FATAL Error($errno) $errfile:$errline $errstr");
72        header("Location: " . SITE_URL . "error.php");
73        exit(1);
74        break;
75
76    case E_USER_WARNING:
77    case E_USER_NOTICE:
78    default:
79    }
80    return true;
81}
82?>
Note: See TracBrowser for help on using the repository browser.