-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy.php
40 lines (30 loc) · 773 Bytes
/
proxy.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
<?php
// quick ajax proxy for accessing remote JSON resources
// @author: joshua giardino
// @license: Apache License 2.0
require_once("/requests/Requests.php");
Requests::register_autoloader();
// is a field set, or empty, null etc
function hasField($field)
{
if(is_null($field) || $field === '' || !isset($field))
{
return FALSE;
} else {
return TRUE;
}
}
$query = $_GET['q'];
header("Content-Type: application/json");
if(hasField($query))
{
$headers = array('Accept' => 'application/json');
$request = Requests::get(urldecode($query), $headers);
echo($request->body);
} else {
$out = array();
$out['status'] = "error";
$out['msg'] = "A required field was not set. [query] - Please check your code and try again.";
echo(json_encode($out));
}
?>