-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy path404_logging.php
More file actions
77 lines (70 loc) · 2.09 KB
/
Copy path404_logging.php
File metadata and controls
77 lines (70 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
// error logging function
function four_oh_four_handler($type, $severity)
{
// determine if the link leading to the not found page is remote or local
if (!empty($_SERVER['HTTP_REFERER'])) {
$remote_or_local = (int) preg_match("!http://[^/]*{$_SERVER['HTTP_HOST']}!", $_SERVER['HTTP_REFERER']);
} else {
$remote_or_local = 2; // direct request
}
$db = new sqlite_db("error_log");
$db->query("INSERT INTO web_errors
(host, request_url, referrer_url, user_ip,
user_browser, notes, request_method,
severity, source, time, type)
VALUES(
'".sqlite_escape_string($_SERVER['HTTP_HOST'])."',
'".sqlite_escape_string($_SERVER['REDIRECT_URL'])."',
'".sqlite_escape_string($_SERVER['HTTP_REFERER'])."',
'".sqlite_escape_string($_SERVER['REMOTE_ADDR'])."',
'".sqlite_escape_string($_SERVER['HTTP_USER_AGENT'])."',
'".sqlite_escape_string($_SERVER['REDIRECT_ERROR_NOTES'])."',
'".sqlite_escape_string($_SERVER['REDIRECT_REQUEST_METHOD'])."',
'{$severity}',
{$remote_or_local},
".time().",
'{$type}'
)
");
}
// determine what sort of an error is this
if (
!strncasecmp($_SERVER['REDIRECT_URL'], '/winnt/', strlen('/winnt/')) ||
!strncasecmp($_SERVER['REDIRECT_URL'], '/scripts/', strlen('/scripts/'))
) {
trigger_error("Yet another unpatched IIS server at '{$_SERVER['REMOTE_ADDR']}', block with firewall");
return;
}
// determine the extension of the not found page.
$extension = strtolower(substr(strrchr($_SERVER['REDIRECT_URL'], '.'), 1));
// actual error handling
switch ($extension) {
case 'php':
case 'cgi':
four_oh_four_handler('DYNAMIC', 1);
// Display a site map to the user so that
// they can find the page they are looking for.
display_site_map();
break;
case 'html':
case 'htm':
case 'shtml':
four_oh_four_handler('STATIC', 2);
display_site_map();
break;
case 'jpg':
case 'gif':
case 'png':
four_oh_four_handler('IMAGE', 3);
// to prevent ugly broken image
// redirect the request to a blank pixel image.
header("Location: /blank.gif");
return;
break;
default:
four_oh_four_handler('UNKNOWN', 4);
display_site_map();
break;
}
?>