-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors-right-way.php
62 lines (54 loc) · 1.77 KB
/
errors-right-way.php
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
<?php
ob_start();
error_reporting(E_ALL);
ini_set('display_errors', 'off');
ini_set('log_errors', 'off');
$error_handler = function ($error = '') {
ob_clean();
$error_crypt = new class {
private $securekey;
private $method = 'AES-256-CBC';
function __construct() {
$this->securekey = hash('sha256', 'bardzo długi klucz do dekodowania błędów systemowych przez programistę.', TRUE);
}
function encrypt(string $data): string
{
$ivSize = openssl_cipher_iv_length($this->method);
$iv = openssl_random_pseudo_bytes($ivSize);
$encrypted = base64_encode($iv . openssl_encrypt($data, $this->method, $this->securekey, OPENSSL_RAW_DATA, $iv));
return $encrypted;
}
function decrypt(string $data): string
{
$data = base64_decode($data);
$ivSize = openssl_cipher_iv_length($this->method);
$iv = substr($data, 0, $ivSize);
$data = openssl_decrypt(substr($data, $ivSize), $this->method, $this->securekey, OPENSSL_RAW_DATA, $iv);
return $data;
}
};
header($_SERVER['SERVER_PROTOCOL'] . " 503 Service Unavailable");
header("Status: 503 Service Unavailable");
echo '<!doctype><html><head><meta charset="UTF-8"><title>503 Service Unavailable</title></head><body>';
echo '<h1>503 Service Unavailable</h1>';
echo '<p>Sorry, something went wrong</p>';
echo '<p>A team of highly trained monkeys has been dispatched to deal with this situation.</p>';
echo '<p>If You see them, show them this information:</p>';
echo '<p style="max-width: 500px; word-break: break-all; font-family: monospace;">';
echo $error_crypt->encrypt($error);
echo '</p>';
echo '</body></html>'
exit;
};
try
{
/* Twój kod */
}
catch (Exception $e)
{
($error_handler)($e);
}
catch (Error $e)
{
($error_handler)($e);
}