-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathng-get.php
30 lines (21 loc) · 879 Bytes
/
ng-get.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
<!-- AUTHORS: WAN LI AND NATALIE ZHANG -->
<?php
header('Access-Control-Allow-Origin: http://localhost:4200');
// header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE, PUT');
// Retrieve data from the request
$getdata = $_GET['str']; // param sent from Angular is named 'str'
// Process data
// (this example simply extracts the data and restructures them back)
// Extract json format to PHP array
$request = json_decode($getdata);
$data = [];
foreach ($request as $k => $v) {
$data[0]['get_' . $k] = $v;
}
// response in php array
// Send response (in json format) back the front end
echo json_encode(['content' => $data]);
?>