
<?php
session_start();
include "connect.php";
$username = $_POST['username'];
$password = $_POST['password'];
$op = $_GET['op'];

if($op=="in"){
    $cek = mysqli_query($koneksi,"SELECT * FROM user WHERE IDUser='$username' AND Password=md5('$password')");
    if(mysqli_num_rows($cek)==1){//jika berhasil akan bernilai 1
        $c = mysqli_fetch_array($cek);
        $_SESSION['username'] = $c['username'];
		$_SESSION['NamaUser'] = $c['NamaUser'];
        $_SESSION['Level'] = $c['Level'];
        if($c['Level']=="admin"){
            header("location:admin.php");
        }else if($c['Level']=="spmb"){
            header("location:userspmb.php");
		}else if($c['Level']=="baak"){
            header("location:userbaak.php");
		}else if($c['Level']=="fin"){
            header("location:userfin.php");
		}else if($c['Level']=="hrd"){
            header("location:userhrd.php");
		}else if($c['Level']=="dosen"){
            header("location:userdosen.php");
		}else if($c['Level']=="kmhs"){
            header("location:pudir3.php");
        }else if($c['Level']=="val"){
            header("location:loginvalidasi.php");
        }
		
    }else{
         die("password salah <a href=\"javascript:history.back()\">kembali</a>");
    }
}else if($op=="out"){
    unset($_SESSION['username']);
    unset($_SESSION['Level']);
    header("location:index.php");
}
?>
