|
1
|
|
|
<? |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
final class Header |
|
4
|
|
|
{ |
|
5
|
|
|
|
|
6
|
|
|
private static $CACHE_EXPIRATION = 315360000; |
|
|
|
|
|
|
7
|
|
|
private static $CACHE_MODIFICATION = 604800; |
|
|
|
|
|
|
8
|
|
|
private static $SITEMAP_EXPIRATION = 604800; |
|
9
|
|
|
private static $RSS_EXPIRATION = 604800; |
|
10
|
|
|
|
|
11
|
|
View Code Duplication |
public static function sendJSON() |
|
|
|
|
|
|
12
|
|
|
{ |
|
13
|
|
|
$array = array( |
|
14
|
|
|
'HTTP/1.1 200 OK', |
|
15
|
|
|
'Cache-Control: no-cache', |
|
16
|
|
|
'Content-Language: en', |
|
17
|
|
|
'Content-Type: application/json', |
|
18
|
|
|
'Expires: ' . self::get_date(time() - 1), |
|
|
|
|
|
|
19
|
|
|
'Last-Modified: ' . self::get_date(), |
|
20
|
|
|
'X-Powered-By: jacobemerick.com'); |
|
21
|
|
|
self::send($array); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
View Code Duplication |
public static function sendSitemap() |
|
|
|
|
|
|
25
|
|
|
{ |
|
26
|
|
|
$array = array( |
|
27
|
|
|
'HTTP/1.1 200 OK', |
|
28
|
|
|
'Cache-Control: max-age=' . self::$SITEMAP_EXPIRATION . ', must-revalidate', |
|
29
|
|
|
'Content-Language: en', |
|
30
|
|
|
'Content-Type: text/xml', |
|
31
|
|
|
'Expires: ' . self::get_date(time() + self::$SITEMAP_EXPIRATION), |
|
|
|
|
|
|
32
|
|
|
'Last-Modified: ' . self::get_date(), |
|
33
|
|
|
'X-Powered-By: jacobemerick.com'); |
|
34
|
|
|
self::send($array); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
View Code Duplication |
public static function sendRSS() |
|
|
|
|
|
|
38
|
|
|
{ |
|
39
|
|
|
$array = array( |
|
40
|
|
|
'HTTP/1.1 200 OK', |
|
41
|
|
|
'Cache-Control: max-age=' . self::$RSS_EXPIRATION . ', must-revalidate', |
|
42
|
|
|
'Content-Language: en', |
|
43
|
|
|
'Content-Type: application/rss+xml', |
|
44
|
|
|
'Expires: ' . self::get_date(time() + self::$RSS_EXPIRATION), |
|
|
|
|
|
|
45
|
|
|
'Last-Modified: ' . self::get_date(), |
|
46
|
|
|
'X-Powered-By: jacobemerick.com'); |
|
47
|
|
|
self::send($array); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
View Code Duplication |
public static function sendHTML() |
|
|
|
|
|
|
51
|
|
|
{ |
|
52
|
|
|
$array = array( |
|
53
|
|
|
'HTTP/1.1 200 OK', |
|
54
|
|
|
'Cache-Control: no-cache', |
|
55
|
|
|
'Content-Language: en', |
|
56
|
|
|
'Content-Type: text/html', |
|
57
|
|
|
'Expires: ' . self::get_date(time() - 1), |
|
|
|
|
|
|
58
|
|
|
'Last-Modified: ' . self::get_date(), |
|
59
|
|
|
'X-Powered-By: jacobemerick.com'); |
|
60
|
|
|
self::send($array); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public static function redirect($location, $method = 301) |
|
64
|
|
|
{ |
|
65
|
|
|
header("Location: {$location}", TRUE, $method); |
|
66
|
|
|
exit(); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
View Code Duplication |
public static function send404() |
|
|
|
|
|
|
70
|
|
|
{ |
|
71
|
|
|
$array = array( |
|
72
|
|
|
'HTTP/1.1 404 Not Found', |
|
73
|
|
|
'Cache-Control: no-cache', |
|
74
|
|
|
'Content-Language: en', |
|
75
|
|
|
'Content-Type: text/html', |
|
76
|
|
|
'Expires: ' . self::get_date(time() - 1), |
|
|
|
|
|
|
77
|
|
|
'Last-Modified: ' . self::get_date(), |
|
78
|
|
|
'X-Powered-By: jacobemerick.com'); |
|
79
|
|
|
self::send($array); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
View Code Duplication |
public static function send503() |
|
|
|
|
|
|
83
|
|
|
{ |
|
84
|
|
|
$array = array( |
|
85
|
|
|
'HTTP/1.1 503 Service Unavailable', |
|
86
|
|
|
'Cache-Control: no-cache', |
|
87
|
|
|
'Content-Language: en', |
|
88
|
|
|
'Content-Type: text/html', |
|
89
|
|
|
'Expires: ' . self::get_date(time() - 1), |
|
|
|
|
|
|
90
|
|
|
'Last-Modified: ' . self::get_date(), |
|
91
|
|
|
'X-Powered-By: jacobemerick.com'); |
|
92
|
|
|
self::send($array); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
private static function send($array, $gzip = true) |
|
96
|
|
|
{ |
|
97
|
|
|
if($gzip) |
|
98
|
|
|
self::start_gzipping(); |
|
99
|
|
|
|
|
100
|
|
|
foreach($array as $row) |
|
101
|
|
|
{ |
|
102
|
|
|
header($row, TRUE); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
private static function get_date($timestamp = false) |
|
107
|
|
|
{ |
|
108
|
|
|
if($timestamp == 0) |
|
109
|
|
|
$timestamp = time(); |
|
110
|
|
|
return gmdate('D, d M Y H:i:s \G\M\T', $timestamp); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
private static function start_gzipping() |
|
114
|
|
|
{ |
|
115
|
|
|
if(!ob_start('ob_gzhandler')) |
|
116
|
|
|
ob_start(); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
} |
|
120
|
|
|
|
Short opening tags are disabled in PHP’s default configuration. In such a case, all content of this file is output verbatim to the browser without being parsed, or executed.
As a precaution to avoid these problems better use the long opening tag
<?php.