Assalamualaikum Warahmatullahi Wabarakatuh...
Mastah2 yg sy hormati, sy ada kesulitan ttg form login multi user dimana mksd sy adalah tiap user ada role sendiri...jd saat login username dan password otomatis di redirect ke dashboard masing2...nah sy udah bikin form login dan user otentikasi tp kok tidak berjalan ya master...mohon pencerahannya...terima kasih...
Wassalam....
Form login :
<?php $pagedesc = "Login"; ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>e - Cuti <?php echo $pagedesc ?></title>
<link href="libs/images/#" rel="icon" type="images/x-icon">
<!-- Bootstrap Core CSS -->
<link href="libs/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="dist/css/offline-font.css" rel="stylesheet">
<link href="dist/css/custom.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="libs/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<!-- jQuery -->
<script src="libs/jquery/dist/jquery.min.js"></script>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body style="background-color: #f1f4f7">
<section id="main-wrapper" style="margin-top: 120px">
<div class="container-fluid">
<div class="row">
<div class="col-lg-4 col-lg-offset-4 col-md-4 col-md-offset-4"><?php include("layout_alert.php"); ?></div>
</div><!-- /.row -->
<div class="row">
<div id="page-wrapper" class="col-lg-4 col-lg-offset-4 col-md-4 col-md-offset-4" style="background-color: #ffffff; border-radius: 3px; webkit-box-shadow: 0 1px 1px rgba(0,0,0,.05); box-shadow: 0 1px 1px rgba(0,0,0,.05)">
<div class="row">
<div class="col-lg-12">
<br/>
<center><img src="libs/images/#" width="145" height="120"></center>
<h2 class="text-center">e - Cuti<br/> <b>#</b></h2>
</div>
</div><!-- /.row -->
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-body">
<form action="login_auth.php" method="post">
<div class="form-group">
<input type="text" class="form-control" name="username" placeholder="Username" required>
</div>
<div class="form-group">
<input type="password" class="form-control" name="password" placeholder="Password" required>
</div>
<div class="form-group">
<input type="submit" class="btn btn-success btn-block" name="login" value="Masuk">
</div>
</form>
</div>
</div>
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.container -->
</section>
<!-- footer-bottom -->
<div class="navbar navbar-inverse navbar-fixed-bottom footer-bottom">
<div class="container text-center">
<p class="text-center" style="color: #D1C4E9; margin: 0 0 5px; padding: 0"><small>e - Cuti</small></p>
</div>
</div><!-- /.footer-bottom -->
<!-- Bootstrap Core JavaScript -->
<script src="libs/bootstrap/dist/js/bootstrap.min.js"></script>
</body>
</html>
Login otentikasi :
<?php
// memulai session
// memanggil file koneksi
include("dist/config/koneksi.php");
// mengecek apakah tombol login sudah di tekan atau belum
if(isset($_POST['login'])) { // mengecek apakah username dan password sudah di isi atau belum
if(empty($_POST['username']) || empty($_POST['password'])) { // mengarahkan ke halaman login.php
header("location: login.php?err=empty"); }
else {
// membaca nilai variabel username dan password
$username = $_POST['username'];
$password = $_POST['password'];
$akses = $_POST['akses'];
// mencegah sql injection
// memeriksa username di tabel admin
if($akses=="Admin"){
$sql = "SELECT * FROM admin WHERE user_adm='". $username ."' AND pass_adm='". $password ."'";
// mendaftarkan session jika username di temukan
if($rows == 1) {
// membuat variabel session
$_SESSION['admin'] = strtolower($dataku['id_adm']); // mengarahkan ke halaman indeks.php
header("location: index.php?login=success"); }else{
header("location: login.php?err=not_found"); }
}else if($akses=="Lead"){
$aks = "Kepala Biro/Prodi";
$sql = "SELECT * FROM employee WHERE hak_akses='".$aks."' AND npp='". $username ."' AND password='". $password ."'";
// mendaftarkan session jika username di temukan
if($rows == 1) {
// membuat variabel session
// mengarahkan ke halaman indeks.php
header("location: leader/index.php?login=success"); }else{
header("location: login.php?err=not_found"); }
}else if($akses=="Mng"){
$aks = "Direktur";
$sql = "SELECT * FROM employee WHERE hak_akses='".$aks."' AND npp='". $username ."' AND password='". $password ."'";
// mendaftarkan session jika username di temukan
if($rows == 1) {
// membuat variabel session
$_SESSION['manager'] = strtolower($dataku['npp']); // mengarahkan ke halaman indeks.php
header("location: manager/index.php?login=success"); }else{
header("location: login.php?err=not_found"); }
}else if($akses=="Pgw"){
$aks = "Pegawai";
$sql = "SELECT * FROM employee WHERE hak_akses='".$aks."' AND npp='". $username ."' AND password='". $password ."'";
// mendaftarkan session jika username di temukan
if($rows == 1) {
// membuat variabel session
$_SESSION['pegawai'] = strtolower($dataku['npp']); // mengarahkan ke halaman indeks.php
header("location: pegawai/index.php?login=success"); }else{
header("location: login.php?err=not_found"); }
}else{
$aks = "Wakil Direktur";
$sql = "SELECT * FROM employee WHERE hak_akses='".$aks."' AND npp='". $username ."' AND password='". $password ."'";
// mendaftarkan session jika username di temukan
if($rows == 1) {
// membuat variabel session
$_SESSION['supervisor'] = strtolower($dataku['npp']); // mengarahkan ke halaman indeks.php
header("location: supervisor/index.php?login=success"); }else{
header("location: login.php?err=not_found"); }
}
}
}
?>