-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetchPiket.php
38 lines (30 loc) · 1.23 KB
/
fetchPiket.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
<?php
$method = $_SERVER['REQUEST_METHOD'];
if ($method == "OPTIONS") {
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: access');
header('Access-Control-Allow-Methods: POST');
header('Content-Type: application/json');
header('Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With');
header('HTTP/1.1 200 OK');
die();
}
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: access');
header('Access-Control-Allow-Methods: POST');
header('Content-Type: application/json');
header('Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With');
require_once __DIR__ . '/src/dbConnect.php';
require_once __DIR__ . '/src/jsonHandler.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') :
$data = json_decode(file_get_contents('php://input'));
$id = trim($data->id);
$sql = "SELECT * FROM piket WHERE `id`='$id'";
$query = mysqli_query($conn, $sql);
$array = array();
while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
$array[] = $row;
}
jsonHandler(200, '', $array);
endif;
jsonHandler(405, 'HTTP method untuk request harus POST');