-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrorcheckclass.php
More file actions
134 lines (113 loc) · 3.74 KB
/
errorcheckclass.php
File metadata and controls
134 lines (113 loc) · 3.74 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/*
File: checkerrorclass.php
Created: 07/21/2020
Updated: 07/21/2020
Programmer: Cuates
Updated By: Cuates
Purpose: Check Error class for all types of PHP fatal errors
*/
// Create the class
class checkerrorclass
{
// PHP 5+ Style constructor
public function __construct()
{
// This function needs to be here so the class can be executed when called
}
// PHP 4 Style constructor
public function checkerrorclass()
{
// Call the constructor
self::__construct();
}
// Email end user of fatal errors
function shutdown_notify($email_to, $email_subject, $from_mail, $from_name, $replyto, $email_cc = "", $email_bcc = "")
{
// Get the last occurred error
$error = error_get_last();
// Check if the error is not empty and is in one of the predefined constants
if(!empty($error) && in_array($error['type'], array(E_ERROR, E_USER_ERROR)))
{
// Set parameters to variables
$to = $email_to;
$subject = $email_subject;
// Set the email headers
$headers = "From: " . $from_name . " <" . $from_mail . ">\r\n";
// Add CC header
if (trim($email_cc) !== "")
{
// Append the CC header
$headers .= "CC: " . $email_cc . "\r\n";
}
// Add BCC header
if (trim($email_bcc) !== "")
{
// Append the BCC header
$headers .= "BCC: " . $email_bcc . "\r\n";
}
// Set reply-to e-mail
$headers .= "Reply-To: " . $replyto . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$message = "Error Message<br />"
. $error['message']
. "<br /><br />Error File<br />"
. $error['file']
. "<br /><br />Error Line<br />"
. $error['line']
. "<br /><br />Host Name<br />";
// Display variable value if set else display nothing
$hostName = gethostname();
$message .= $hostName !== false ? $hostName : '';
// Send email to software engineers for unsent email
mail($to, $subject, $message, $headers);
}
}
// Email end user of fatal errors
function caught_error_notify($e, $email_to, $email_subject, $from_mail, $from_name, $replyto, $email_cc = "", $email_bcc = "")
{
// Set parameters to variables
$to = $email_to;
$subject = $email_subject;
// Set the email headers
$headers = "From: " . $from_name . " <" . $from_mail . ">\r\n";
// Add CC header
if (trim($email_cc) !== "")
{
// Append the CC header
$headers .= "CC: " . $email_cc . "\r\n";
}
// Add BCC header
if (trim($email_bcc) !== "")
{
// Append the BCC header
$headers .= "BCC: " . $email_bcc . "\r\n";
}
// Set reply-to e-mail
$headers .= "Reply-To: " . $replyto . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
// Set the email body message
$message = "Error Message
<br />
{$e->getMessage()}
<br />
<br />
Error File
<br />
{$e->getFile()}
<br />
<br />
Error Line
<br />
{$e->getLine()}
<br /><br />Host Name<br />";
// Display variable value if set else display nothing
$hostName = gethostname();
$message .= $hostName !== false ? $hostName : '';
// Send email to developer about unsent email
mail($to, $subject, $message, $headers);
}
}
?>