Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header('Content-Type: application/json; charset=utf-8');
- $connect = '';
- function checkUser($method)
- {
- // global $connect;
- $response = [
- 'status' => 0,
- 'message' => ''
- ];
- $headers = getallheaders();
- // https://stackoverflow.com/questions/53610622/what-does-double-question-mark-operator-mean-in-php
- $type = $headers['Type'] ?? null;
- $id = $headers["Device"] ?? null;
- // jika $type atau $id == null
- // return false
- if (!$type || !$id) {
- $response['message'] = 'id and type can not be blank';
- return json_encode($response);
- }
- // jika $type ==mercu
- if ($type == 'Mercu') {
- $headers["User-Agent"] == $headers["Device"];
- $datas = null; // inisiasi karena data line 24 blm di define
- $sql = "SELECT * FROM member where Device = $id";
- // $result = $connect->query($sql);
- // while ($row = mysqli_fetch_object($result)) {
- for ($x = 1; $x <= 10; $x++) {
- $row = new stdClass;
- $row->xxx = 'qwerty ' . $x;
- $datas[] = [
- 'Mercu' => $row->xxx,
- 'Admin' => $row->xxx,
- 'Expired' => $row->xxx,
- 'Message' => $row->xxx,
- ];
- }
- // }
- // $data = ['ok'];
- if (!$datas) {
- $response['message'] = 'No data to display';
- return json_encode($response);
- }
- // anggap lah column di member isi nya
- // id,name,expired_date,created_date
- // [{"Mercu":"12345","Admin":"@KopiNih","Expired":"15-12-2021","Message":"Mercu"}]}
- $response['status'] = 1;
- $response['data'] = $datas;
- return json_encode($response);
- }
- // return false
- // jika $type != mercu
- $response['message'] = 'invalid type';
- return json_encode($response);
- }
- echo checkUser('get');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement