-
Notifications
You must be signed in to change notification settings - Fork 24
/
test.php
40 lines (33 loc) · 970 Bytes
/
test.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
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, PATCH');
$method = $_SERVER['REQUEST_METHOD'];
// Parse GET params
$source = $_SERVER['QUERY_STRING'];
parse_str($source, $params);
// Parse POST, PUT, DELETE params
if ($method !== 'GET' && $method !== 'DELETE') {
$source_input = file_get_contents('php://input');
parse_str($source_input, $params_input);
$params = array_merge($params, $params_input);
}
// Read header Access-Token
if (isset($_SERVER['HTTP_ACCESS_TOKEN'])) {
$params['token'] = $_SERVER['HTTP_ACCESS_TOKEN'];
}
$params['__METHOD__'] = $method;
switch ($method) {
case 'PUT':
echo json_encode($params);
break;
case 'POST':
echo json_encode($params);
break;
case 'GET':
echo json_encode($params);
break;
default:
echo json_encode($params);
break;
}