<?php

session_start();

include 'config/koneksi.php';

$username =
mysqli_real_escape_string(
$conn,
$_POST['username']
);

$password = md5($_POST['password']);

$query = mysqli_query($conn,

"SELECT * FROM users

WHERE username='$username'
AND password='$password'"

);

$data = mysqli_fetch_assoc($query);

if($data){

    $_SESSION['id'] = $data['id'];

    $_SESSION['nama'] = $data['nama'];

    $_SESSION['role'] = $data['role'];

    /* ADMIN */

    if($data['role']=='admin'){

        header("Location: admin/dashboard.php");
        exit;
    }

    /* WARGA */

    elseif($data['role']=='warga'){

        header("Location: warga/dashboard.php");
        exit;
    }

    /* CS */

    elseif($data['role']=='cs'){

        header("Location: cs/dashboard.php");
        exit;
    }

}else{

    echo "

    <script>

    alert('Login gagal');

    window.location='index.php';

    </script>

    ";
}
?>