-
Notifications
You must be signed in to change notification settings - Fork 3
/
get-kota.php
37 lines (28 loc) · 911 Bytes
/
get-kota.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
<?php
$curl = curl_init();
$provinsi = $_GET['id'];
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.rajaongkir.com/starter/city?province=$provinsi",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"key: b9e4d5305b25625d54c7bb77a9302b94"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "Gagal Mengambil daftar Kota";
}else{
$hasil = json_decode($response, true);
echo "<option value='' disabled selected>Pilih Kota Anda</option>";
for($i=0; $i<count($hasil['rajaongkir']['results']); $i++){
echo "<option value='".$hasil['rajaongkir']['results'][$i]['city_id']."'>".$hasil['rajaongkir']['results'][$i]['city_name']."</option><br/>";
}
}
?>