<?php
    function RedirectLivedraw($koneksi, $db_waktu, $db_tanggal, $redirect){
        $qry_hadiah = mysqli_query(
            $koneksi,
            "SELECT * FROM $db_waktu WHERE id_situs ='1'"
        );
        $dt_bank = mysqli_fetch_array($qry_hadiah);
        $draw_time = $dt_bank["draw_time"];
        $draw_end = $dt_bank["draw_end"];
        $jam_target_awal = $draw_time;
        $jam_target_akhir = $draw_end;
        $time_now = date("H:i");
        $date_now = date('Y-m-d');
        $jadwal_draw = mysqli_query(
            $koneksi,
            "SELECT * FROM $db_tanggal
            WHERE DATE_FORMAT(STR_TO_DATE(tanggal, '%a, %d %b %Y'), '%Y-%m-%d') = '$date_now'
            ORDER BY id DESC LIMIT 1"
        );
        
        if (date("H:i") >= $jam_target_awal && date("H:i") <= $jam_target_akhir) {
            if(!empty($jadwal_draw)){
                    echo "
                    <script>
                        window.location.href = '$redirect';
                    </script>
                    ";
            }
        }
    }
?>