-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patherror.php
More file actions
137 lines (131 loc) · 4.61 KB
/
error.php
File metadata and controls
137 lines (131 loc) · 4.61 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
135
136
137
<?php
/**
* Евгений Ефимченко, efimchenko.com
* Обработчик страницы ошибок, перенаправляет пользователей на главную страницу сайта с сообщением.
* /error.php
*/
use classes\system\Session;
if (!defined('ENV_SITE') || !ENV_SITE) {
http_response_code(404);
die;
}
$statusLine = (string) (Session::get('code') ?: '');
$statusCode = 0;
$statusCodeFromSession = false;
if (preg_match('/^(\d{3})\b/', $statusLine, $matches)) {
$statusCode = (int) $matches[1];
$statusCodeFromSession = true;
}
if ($statusCode < 400 || $statusCode > 599) {
$statusCode = http_response_code();
if ($statusCode < 400 || $statusCode > 599) {
$statusCode = 404;
}
}
$statusText = match ($statusCode) {
400 => 'Bad Request',
401 => 'Unauthorized',
403 => 'Forbidden',
404 => 'Not Found',
500 => 'Internal Server Error',
503 => 'Service Unavailable',
default => 'Error',
};
$statusLine = $statusCode . ' ' . $statusText;
if (!$statusCodeFromSession && !headers_sent()) {
http_response_code($statusCode);
}
$pageTitle = match ($statusCode) {
404 => 'Страница не найдена',
503 => 'Сервис временно недоступен',
500 => 'Внутренняя ошибка сервера',
default => 'Ошибка запроса',
};
$pageMessage = match ($statusCode) {
404 => 'Запрошенная страница не найдена или была перемещена.',
503 => 'Сервис временно недоступен. Попробуйте обновить страницу позже.',
500 => 'На сервере произошла ошибка. Подробности сохранены в журнале.',
default => 'Не удалось обработать запрос.',
};
$showAutoRefresh = in_array($statusCode, [404], true);
?>
<!DOCTYPE html>
<html lang="<?= defined('ENV_DEF_LANG') ? strtolower((string) ENV_DEF_LANG) : 'ru' ?>">
<head>
<title><?= htmlspecialchars($statusLine, ENT_QUOTES, 'UTF-8') ?></title>
<meta charset="utf-8">
<?php if ($showAutoRefresh): ?>
<meta http-equiv="refresh" content="5;<?= htmlspecialchars((string) ENV_URL_SITE, ENT_QUOTES, 'UTF-8') ?>">
<?php endif; ?>
<meta name="viewport" content="width=device-width, initial-scale=0.5">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<style type="text/css">
html, body {
width:100%;
height:100%;
overflow:hidden;
margin:0px;
padding:0px;
font-family:'Open Sans',sans-serif;
font-size:16px
}
body {
background:#fff;
color:#111;
}
.content {
width:min(720px, calc(100% - 32px));
text-align:center;
position:absolute;
top:50%;
left:50%;
transform:translate(-50%, -50%);
}
.status-code {
font-size:72px;
font-weight:700;
line-height:1;
margin:0 0 20px;
}
.status-title {
font-size:28px;
font-weight:700;
margin:0 0 12px;
}
.status-message {
font-size:18px;
line-height:1.5;
margin:0 0 24px;
}
.content a {
display:inline-block;
text-decoration:none;
border:1px solid #111;
border-radius:4px;
padding:10px 16px;
}
.content a:hover {
opacity:0.7
}
.content a, .content a:hover {
color:#000;
}
@media only screen and (max-width: 460px), screen and (max-height: 700px) {
.content {
position:absolute;
}
.status-code {
font-size:48px;
}
}
</style>
</head>
<body>
<div class="content">
<div class="status-code"><?= (int) $statusCode ?></div>
<h1 class="status-title"><?= htmlspecialchars($pageTitle, ENT_QUOTES, 'UTF-8') ?></h1>
<p class="status-message"><?= htmlspecialchars($pageMessage, ENT_QUOTES, 'UTF-8') ?></p>
<a href="/">На главную страницу</a>
</div>
</body>
</html>