-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrpage.php
More file actions
47 lines (43 loc) · 1.13 KB
/
errpage.php
File metadata and controls
47 lines (43 loc) · 1.13 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
<?php
namespace ScpoPHP;
require_once __DIR__ . '/url.php';
use ScpoPHP\Config\Errpage as Cfg;
/**
* 快速优雅地抛出错误
* @link http://scpo-php.seventop.top/errpage/
*/
class Errpage
{
/**各错误码对应信息 */
static $code_info = array(
404 => 'Not Found',
418 => 'I\'m a teapot'
);
/**
* 发出错误
*/
static public function die($code)
{
$info = isset(self::$code_info[$code]) ? ' ' . self::$code_info[$code] : '';
header("HTTP/1.1 $code$info");
echo "\"^_^ <b>Surprise!</b><br />$code $info\"";
die();
}
/**
* 快速重定向
*/
static public function get_ret($file, $from = '')
{
static $c_url = '//' . $_SERVER['HTTP_HOST'] . Cfg::$now->callback_page;
$ret = function ($info) use ($c_url, $file) {
header('Location: ' . Url::rep_query($c_url, [Cfg::$now->query_key => "$file:\n$info"]));
die();
};
$end = function ($info_raw) use ($from, $ret) {
if (!$from) $ret('No $from but using end function in ScpoPHP\Errpage:' . __LINE__);
header("Location: " . Url::rep_query($from, [Cfg::$now->query_key => (Cfg::$now->encoder)($info_raw)]));
die();
};
return [$ret, $end];
}
}