Tugas 9 PWEB C
Membuat autorisasi level pada web
link web: https://achferdiauth.000webhostapp.com/
tampilan awal:
tampilan beranda admin:
tampilan beranda staff:
- index.php
<?php
session_start();
$login = $_SESSION['login'];
if ($login == 1) {
include "koneksi.php";
?>
<!DOCTYPE html>
<html>
<head>
<title>Aplikasi Login Sederhana</title>
<style>
body {
font-family: verdana;
font-size: 12px;
}
a {
text-decoration: none;
color: blue;
}
a:hover {
color: green;
}
</style>
</head>
<body>
<h1 align="center">Aplikasi Login Dengan Level Akses</h1>
<hr>
<?php
$level = $_SESSION['level'];
if ($level == 1) {
include "menu_admin.php";
}
if ($level == 2) {
include "menu_staff.php";
}
?>
<hr>
<?php
$nama = $_SESSION['nama'];
$username = $_SESSION['username'];
echo "Selamat Datang $nama ($username) ";
?>
<hr>
</body>
</html>
<?php
} else {
include "login.php";
}
?>
- koneksi.php
<?php
$host = "localhost";
$user = "root";
$pass = "";
$db = "db_web";
$koneksi = mysqli_connect($host, $user, $pass, $db);
?>
- login-proses.php
<?php
session_start();
include "koneksi.php";
$username = $_POST['username'];
$password = $_POST['password'];
//cek data
$sql = "SELECT * FROM user WHERE username='$username' ";
$qry = mysqli_query($koneksi, $sql);
$usr = mysqli_fetch_array($qry);
if (
md5($username) == md5($usr['username'])
and
md5($password) == md5($usr['password'])
) {
$_SESSION['iduser'] = $usr['iduser'];
$_SESSION['username'] = $usr['username'];
$_SESSION['nama'] = $usr['nama'];
$_SESSION['level'] = $usr['level'];
$_SESSION['login'] = 1;
$pesan = "Login berhasil, selamat datan $username";
} else {
$pesan = "Login gagal, username atau password anda salah!";
}
?>
<script>
alert('<?php echo $pesan; ?>');
location = 'index.php';
</script>
- login.php
<!DOCTYPE html>
<html>
<head>
<title>Aplikasi Login Sederhana</title>
<style>
body {
font-family: verdana;
font-size: 12px;
}
a {
text-decoration: none;
color: blue;
}
a:hover {
color: green;
}
</style>
</head>
<body>
<h1 align="center">Aplikasi Login Sederhana : PHP Session</h1>
<hr>
<form action="login-proses.php" method="post">
<table width="300" border="0" align="center">
<tr>
<td width="150">Username</td>
<td>
<input type="text" name="username" required>
</td>
</tr>
<tr>
<td width="150">Password</td>
<td>
<input type="password" name="password" required>
</td>
</tr>
<tr>
<td width="150"></td>
<td>
<input type="submit" value="login" required>
</td>
</tr>
</table>
</form>
</body>
</html>
- logout.php
<?php
session_start();
session_destroy();
?>
<script>
alert('Logout berhasil');
location = 'index.php';
</script>
- menu_admin.php
<a href="index.php">Beranda</a> |
<a href="index.php?menu=user">Data User</a> |
<a href="index.php?menu=rekapitulasi">Data Rekapitulasi</a> |
<a href="logout.php">Logout</a> |
- menu_staff.php
<a href="index.php">Beranda</a> |
<a href="index.php?menu=absensi">Data Absensi</a> |
<a href="logout.php">Logout</a> |
Comments
Post a Comment