-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
58 lines (50 loc) · 1.91 KB
/
index.php
File metadata and controls
58 lines (50 loc) · 1.91 KB
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
<?php
session_start();
if (isset($_SESSION['user'])) {
header('Location: user.php');
exit;
}
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$user = $_POST['user'] ?? '';
$password = $_POST['password'] ?? '';
if ($user !== '' && $user === $password) {
$_SESSION['user'] = $user;
header('Location: user.php');
exit;
}
$error = 'Login gagal, user dan password tidak cocok.';
}
?>
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<title>Login</title>
<style>
body { font-family: sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background: #f4f4f4; }
.login-box { background: #fff; padding: 2rem; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,.1); width: 320px; }
h1 { margin-top: 0; font-size: 1.25rem; }
label { display: block; margin-top: .75rem; font-size: .9rem; }
input[type=text], input[type=password] { width: 100%; padding: .5rem; box-sizing: border-box; border: 1px solid #ccc; border-radius: 4px; }
button { margin-top: 1rem; width: 100%; padding: .6rem; background: #2563eb; color: #fff; border: 0; border-radius: 4px; cursor: pointer; }
button:hover { background: #1d4ed8; }
.error { color: #b91c1c; margin-top: .75rem; font-size: .9rem; }
</style>
</head>
<body>
<div class="login-box">
<h1>Login</h1>
<form method="post" action="index.php">
<label for="user">User</label>
<input type="text" id="user" name="user" required>
<label for="password">Password</label>
<input type="password" id="password" name="password" required>
<button type="submit">Login</button>
<?php if ($error !== ''): ?>
<div class="error"><?= htmlspecialchars($error) ?></div>
<?php endif; ?>
</form>
</div>
</body>
</html>