コード例 #1
0
function kota($dari, $ke, $kg, $user_agent)
{
    $json_dari = "http://www.jne.co.id/server/server_city_from.php?term={$dari}";
    $json_daric = file_get_contents($json_dari);
    $hasil_dari = json_decode($json_daric);
    $json_ke = "http://www.jne.co.id/server/server_city.php?term={$ke}";
    $json_kec = file_get_contents($json_ke);
    $hasil_ke = json_decode($json_kec);
    if ($hasil_dari == null || $hasil_ke == null) {
        return errorcoy();
    } else {
        $daric = $hasil_dari[0]->code;
        $darib = $hasil_dari[0]->label;
        $kec = $hasil_ke[0]->code;
        $keb = $hasil_ke[0]->label;
        return jne($daric, $kec, $darib, $keb, $kg, $user_agent);
    }
}
コード例 #2
0
		<option value="2">2</option>
		<option value="3">3</option>
		<option value="4">4</option>
		<option value="5">5</option>
	</select>
	<select name="service">
		<option value="tiki">TIKI</option>
		<option value="jne">JNE</option>
	</select>
	<button>CEK</button>
</form>

<?php 
// Memanggil fungsi
require "ongkir.php";
if (!empty($_GET['service']) && !empty($_GET['dari']) && !empty($_GET['ke']) && !empty($_GET['berat'])) {
    $service = $_GET['service'];
    $dari = $_GET['dari'];
    $ke = $_GET['ke'];
    $kg = $_GET['berat'];
    $user_agent = "Googlebot/2.1 (http://www.googlebot.com/bot.html)";
    if ($service == 'tiki') {
        // menampilkan ongkir TIKI
        echo "<p>Dari: {$dari}<br>Ke: {$ke}<br>Berat (Kg): {$kg}</p>" . tiki($dari, $ke, $kg, $user_agent);
    } else {
        if ($service == 'jne') {
            // menampilkan ongkir JNE
            echo jne($dari, $ke, $kg, $user_agent);
        }
    }
}