-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
184 lines (153 loc) · 5.71 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<!-- SCRIPT UNTUK MEMBUAT FORM LOGIN BERFUNGSI -->
<?php
// mengaktifkan session pada PHP
session_start();
// menghubungkan php dengan koneksi database
include "koneksi.php";
// mengecek apakah ada request post / kalau tombol submit di klik akan dilakukan proses
if( $_SERVER["REQUEST_METHOD"] == "POST" ) {
$username = $_POST["username"]; // tampung data yang dikirim
$password = $_POST["password"];
if( $username == '' || $password == '' ) { // cek apakah username / password kosong
echo "<script>window.alert('Warning! Form Anda Belum Lengkap!')</script>"; // tampilkan pesan
}else { // ketika datanya sudah lengkap, maka dicek
$login = mysqli_query($koneksi,
"SELECT * FROM user WHERE
username = '$username' AND
password = '$password' ");
$jml = mysqli_num_rows($login);
if( $jml > 0 ) { // kalau hasil cek nya ketemu atau > 0
$data = mysqli_fetch_array($login);
// cek jika user login sebagai Admin
if( $data['level'] == "Admin" ) {
// buat session login dan username
$_SESSION['login'] = TRUE;
$_SESSION['id_user'] = $data['id_user'];
$_SESSION['nama_lengkap'] = $data['nama_lengkap'];
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
$_SESSION['level'] = "Admin";
// alihkan ke halaman dashboard Admin
echo "<script>window.alert('Selamat, Anda Berhasil Login Sebagai Admin!'); window.location='admin/dashboard.php'</script>";
// cek jika user login sebagai Kasir
}elseif ( $data['level'] == "Kasir" ) {
// buat session login dan username
$_SESSION['login'] = TRUE;
$_SESSION['id_user'] = $data['id_user'];
$_SESSION['nama_lengkap'] = $data['nama_lengkap'];
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
$_SESSION['level'] = "Kasir";
// alihkan ke halaman dashboar Kasir
echo "<script>window.alert('Selamat, Anda Berhasil Login Sebagai Kasir!'); window.location='kasir/dashboard.php'</script>";
}else {
// alihkan ke halaman login kembali
echo "<script>window.alert('Username atau Password Anda Tidak Cocok!');</script>"; // maka akan tampil alert.
}
}else {
// alihkan ke halaman login kembali
echo "<script>window.alert('Username atau Password Anda Tidak Cocok!');</script>"; // maka akan tampil alert.
}
}
}
?>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<!-- My Fonts -->
<link rel="stylesheet" type="text/css" href="fontawesome-free/css/all.min.css">
<!-- My Icon -->
<link href="img/icon.png" rel="icon">
<!-- My Css -->
<style type="text/css">
hr {
width: 190px;
border-top: 3px solid brown;
}
.bodylogin {
background-color: #DEB887;
}
.login {
margin-top: 13%;
box-shadow: 0 4px 20px rgba(0,0,0,0.3);
width: 90%;
padding: 20px;
background-color: #FAEBD7;
}
.login hr {
width: 50%;
border: 1px solid brown;
}
.formlogin button {
width: 49%;
}
/* DESKTOP VERSION */
@media (min-width: 992px) {
.login {
width: 30%;
margin-top: 4%;
box-shadow: 0 3px 20px rgba(0,0,0,0.3);
padding: 40px;
}
.login hr {
width: 100%;
border: 1px solid brown;
}
.formlogin button {
width: 49%;
}
}
</style>
<title>Login Angkringan Lek'Tok</title>
</head>
<body class="bodylogin">
<!-- LOGO DAN TULISAN -->
<div class="container login">
<div class="row">
<div class="col text-center">
<img src="img/icon.png" class="img.circle mb-3" alt="Logo" width="140px;">
<h5>LOGIN APLIKASI POS</h5>
<hr>
</div>
</div>
<!-- AKHIR LOGO DAN TULISAN -->
<!-- FORM LOGIN -->
<form action="" method="post" role="form" class="formlogin">
<!-- Username -->
<div class="form-group">
<label>Username</label>
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-user"></i></div>
</div>
<input type="text" name="username" class="form-control" placeholder="Masukkan Username Anda">
</div>
</div>
<!-- Password -->
<div class="form-group">
<label>Password</label>
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-unlock-alt"></i></div>
</div>
<input type="password" name="password" class="form-control" placeholder="Masukkan Password Anda">
</div>
</div>
<!-- Button -->
<button type="submit" class="btn btn-primary" value="submit">SUBMIT</button>
<button type="reset" class="btn btn-danger" value="reset">RESET</button>
</form>
</div>
<!-- AKHIR FORM LOGIN -->
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>
<script type="text/javascript" src="js/popper.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
</body>
</html>