1
|
|
|
<? |
|
|
|
|
2
|
|
|
|
3
|
|
|
final class Header |
4
|
|
|
{ |
5
|
|
|
|
6
|
|
View Code Duplication |
public static function sendJSON() |
|
|
|
|
7
|
|
|
{ |
8
|
|
|
$array = array( |
9
|
|
|
'HTTP/1.1 200 OK', |
10
|
|
|
'Cache-Control: no-cache', |
11
|
|
|
'Content-Language: en', |
12
|
|
|
'Content-Type: application/json', |
13
|
|
|
'Expires: ' . self::get_date(time() - 1), |
|
|
|
|
14
|
|
|
'Last-Modified: ' . self::get_date(), |
15
|
|
|
'X-Powered-By: jacobemerick.com'); |
16
|
|
|
self::send($array); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
View Code Duplication |
public static function sendHTML() |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
$array = array( |
22
|
|
|
'HTTP/1.1 200 OK', |
23
|
|
|
'Cache-Control: no-cache', |
24
|
|
|
'Content-Language: en', |
25
|
|
|
'Content-Type: text/html', |
26
|
|
|
'Expires: ' . self::get_date(time() - 1), |
|
|
|
|
27
|
|
|
'Last-Modified: ' . self::get_date(), |
28
|
|
|
'X-Powered-By: jacobemerick.com'); |
29
|
|
|
self::send($array); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public static function redirect($location, $method = 301) |
33
|
|
|
{ |
34
|
|
|
header("Location: {$location}", TRUE, $method); |
35
|
|
|
exit(); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
View Code Duplication |
public static function send404() |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
$array = array( |
41
|
|
|
'HTTP/1.1 404 Not Found', |
42
|
|
|
'Cache-Control: no-cache', |
43
|
|
|
'Content-Language: en', |
44
|
|
|
'Content-Type: text/html', |
45
|
|
|
'Expires: ' . self::get_date(time() - 1), |
|
|
|
|
46
|
|
|
'Last-Modified: ' . self::get_date(), |
47
|
|
|
'X-Powered-By: jacobemerick.com'); |
48
|
|
|
self::send($array); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
View Code Duplication |
public static function send503() |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
$array = array( |
54
|
|
|
'HTTP/1.1 503 Service Unavailable', |
55
|
|
|
'Cache-Control: no-cache', |
56
|
|
|
'Content-Language: en', |
57
|
|
|
'Content-Type: text/html', |
58
|
|
|
'Expires: ' . self::get_date(time() - 1), |
|
|
|
|
59
|
|
|
'Last-Modified: ' . self::get_date(), |
60
|
|
|
'X-Powered-By: jacobemerick.com'); |
61
|
|
|
self::send($array); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
private static function send($array, $gzip = true) |
65
|
|
|
{ |
66
|
|
|
if($gzip) |
67
|
|
|
self::start_gzipping(); |
68
|
|
|
|
69
|
|
|
foreach($array as $row) |
70
|
|
|
{ |
71
|
|
|
header($row, TRUE); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
private static function get_date($timestamp = false) |
76
|
|
|
{ |
77
|
|
|
if($timestamp == 0) |
78
|
|
|
$timestamp = time(); |
79
|
|
|
return gmdate('D, d M Y H:i:s \G\M\T', $timestamp); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
private static function start_gzipping() |
83
|
|
|
{ |
84
|
|
|
if(!ob_start('ob_gzhandler')) |
85
|
|
|
ob_start(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
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
.