-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread.php
45 lines (37 loc) · 1.01 KB
/
read.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
41
42
43
44
45
<?php
function getKey() {
return ["apikey1234", "apikey5678", "myapikey"];
}
function isValid($input) {
$apikey = $input["api_key"];
if (in_array($apikey, getKey())) {
return true;
} else {
return false;
}
}
function jsonOut($status, $message, $data) {
$respon = ["status" => $status, "message" => $message, "data" => $data];
header("Content-type: application/json");
echo json_encode($respon);
}
function getData() {
include 'conn.php';
$sql = "select * from produk";
$koneksi = mysqli_query($conn, $sql);
while ($data = mysqli_fetch_array($koneksi)){
$datanya[]=array(
'id' => $data['id'],
'nama' => $data['nama'],
'kategori' => $data['kategori'],
'harga' => $data['harga']
);
}
return $datanya;
}
if (isValid($_GET)) {
jsonOut("Success", "Api Key Valid", getData());
} else {
jsonOut("Not Success", "Api Key Not Valid", null);
}
?>