-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput.php
42 lines (37 loc) · 851 Bytes
/
output.php
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
<?php
class Output {
function Output(){
$this->results = array();
}
function send_output($type){
switch ($type){
case "json":
header("Content-type: application/json", true);
echo json_encode($this->results);
break;
default:
$this->error("error", "Output content-type not allowed.");
}
exit();
}
function error($type='', $text=''){
switch ($type){
case "error":
$this->set_header_status("400", "Bad Request");
echo '{"error": "'.$text.'"}';
break;
case "unauthorized":
$this->set_header_status("401", "Unauthorized");
echo '{unauthorized: "'.$text.'"}';
break;
default:
$this->set_header_status('400', 'Bad Request');
echo '{"error": "Bad Request"}';
}
exit();
}
function set_header_status($code, $text) {
header("HTTP/1.1 $code $text", true, $code);
}
}
?>