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
|
|
|
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 sendHTML() |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$array = array( |
40
|
|
|
'HTTP/1.1 200 OK', |
41
|
|
|
'Cache-Control: no-cache', |
42
|
|
|
'Content-Language: en', |
43
|
|
|
'Content-Type: text/html', |
44
|
|
|
'Expires: ' . self::get_date(time() - 1), |
|
|
|
|
45
|
|
|
'Last-Modified: ' . self::get_date(), |
46
|
|
|
'X-Powered-By: jacobemerick.com'); |
47
|
|
|
self::send($array); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public static function redirect($location, $method = 301) |
51
|
|
|
{ |
52
|
|
|
header("Location: {$location}", TRUE, $method); |
53
|
|
|
exit(); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
View Code Duplication |
public static function send404() |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
$array = array( |
59
|
|
|
'HTTP/1.1 404 Not Found', |
60
|
|
|
'Cache-Control: no-cache', |
61
|
|
|
'Content-Language: en', |
62
|
|
|
'Content-Type: text/html', |
63
|
|
|
'Expires: ' . self::get_date(time() - 1), |
|
|
|
|
64
|
|
|
'Last-Modified: ' . self::get_date(), |
65
|
|
|
'X-Powered-By: jacobemerick.com'); |
66
|
|
|
self::send($array); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
View Code Duplication |
public static function send503() |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
$array = array( |
72
|
|
|
'HTTP/1.1 503 Service Unavailable', |
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
|
|
|
private static function send($array, $gzip = true) |
83
|
|
|
{ |
84
|
|
|
if($gzip) |
85
|
|
|
self::start_gzipping(); |
86
|
|
|
|
87
|
|
|
foreach($array as $row) |
88
|
|
|
{ |
89
|
|
|
header($row, TRUE); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
private static function get_date($timestamp = false) |
94
|
|
|
{ |
95
|
|
|
if($timestamp == 0) |
96
|
|
|
$timestamp = time(); |
97
|
|
|
return gmdate('D, d M Y H:i:s \G\M\T', $timestamp); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
private static function start_gzipping() |
101
|
|
|
{ |
102
|
|
|
if(!ob_start('ob_gzhandler')) |
103
|
|
|
ob_start(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
} |
107
|
|
|
|
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
.