changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / debug / xerror.php
1 <?php
2 /*
3    The error handler provided here will feed all errors and warnings
4    into HTTP headers of the form "X-Error-NNNNN: ...", so they can't
5    disturb page output or make XML output invalid. This allows to
6    turn on complete error_reporting() without any functionality loss
7    due to premature output.
8    You of course need a good Web browser that can easily display all
9    response headers then for developing - 'w3m' makes an excellent
10    choice! (press "=" there)
11 */
12
13 set_error_handler("ewiki_http_header_errors");
14 ini_set("html_errors", 0);
15
16 function ewiki_http_header_errors($errno, $msg, $file, $line, $lvars) {
17
18    static $error_types = array(
19       E_PARSE => "PARSE ERROR",
20       E_ERROR => "ERROR",
21       E_WARNING => "WARNING",
22       E_NOTICE => "NOTICE",
23       E_STRICT => "STRICT",
24       E_USER_ERROR => "USER ERROR",
25       E_USER_WARNING => "USER WARNING",
26       E_USER_NOTICE => "USER NOTICE",
27    );
28    ($errtype = $error_types[$errno]) or ($errtype = "UNDEF ERROR");
29    
30    #-- check for @ and disabled errors
31    $emask = get_cfg_var("error_reporting");
32    if (! ($emask & $errno)) {
33       return;
34    }
35
36    #-- output
37    $msg = strtr($msg, "\r\n\t\f", "    ");
38    $msg = "$errtype: $msg in $file, line #$line";
39    if (headers_sent()) {
40       print "\n<!--<div class=\"php-error\">$msg</div>-->\n";
41    }
42    else {
43       $no = crc32($msg);
44       $no = ($no & 0xFFFF) ^ ($no >> 16);
45       header("X-Error-$no: $msg");
46       if ($errno == E_FATAL) { header("Status: 500 Something bad happened"); }
47    }
48 }
49
50 ?>