<?php
require("config/koneksi.php");
require("config/function.php");
//cek_session_admin();
$token = isset($_GET['token']) ? $_GET['token'] : 'false';
$npsn = isset($_GET['npsn']) ? $_GET['npsn'] : 'false';
$querys = mysqli_query($koneksi, "select token_api from aplikasi where token_api='$token'");
$cektoken = mysqli_num_rows($querys);

if ($cektoken <> 0) {

    $sql_npsn = '';
    if (!empty($npsn)) {
        $sql_npsn = " where npsn='$npsn'";
    }
    $query = mysqli_query($koneksi, "select * from siswa " . $sql_npsn);
    $array_data = array();
    while ($baris = mysqli_fetch_assoc($query)) {
        $array_data[] = $baris;
    }

    echo json_encode([
        'siswa' => $array_data
    ]);
} else {
    echo "<script>location.href='.'</script>";
}
