Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------------------------------//No2 index.html-------------------------------------
- <!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.0">
- <title>Faris Rasyid | 50421483</title>
- </head>
- <body>
- <h1>Cari Lokasi Universitas</h1>
- <form action="hasil.php" method="GET">
- <fieldset>
- <label for="university">Masukkan nama universitas:</label>
- <input type="text" id="university" name="university" required><br><br>
- </fieldset>
- <input type="submit" value="Cari Lokasi">
- </form>
- </body>
- </html>
- -----------------------------------------//No2 hasil.php--------------------------------------
- <?php
- echo "<h1>Lokasi Universitas</h1>";
- if ($_SERVER["REQUEST_METHOD"] == "GET") {
- $university = $_GET['university'];
- $lokasi = "";
- if ($university == "gundar" || $university == "universitas gunadarma") {
- $lokasi = "Depok";
- } elseif ($university == "ui" || $university == "universitas indonesia") {
- $lokasi = "Depok";
- } elseif ($university == "gunadarma" || $university == "universitas indonesia") {
- $lokasi = "Depok";
- } elseif ($university == "itb" || $university == "institut teknologi bandung") {
- $lokasi = "Bandung";
- } elseif ($university == "undip" || $university == "universitas diponogoro") {
- $lokasi = "Semarang";
- } elseif ($university == "ugm" || $university == "universitas gajah mada") {
- $lokasi = "Yogyakarta";
- } else {
- $lokasi = "tidak diketahui";
- }
- if ($lokasi == "Tidak diketahui") {
- echo "<p>Lokasi dari $university $lokasi</p>";
- } else {
- echo "<p>$university berada di $lokasi</p>";
- }
- }
- ---------------------------------------//admin.php-----------------------------------
- <?php
- // Memeriksa apakah pengguna sudah login atau belum
- session_start();
- if (!isset($_SESSION['username'])) {
- header('Location: /act5/no3/index.php'); // Jika belum login, redirect ke halaman login
- exit;
- }
- ?>
- <!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.0">
- <title>Faris Rasyid | 50421483</title>
- </head>
- <body>
- <h1>Selamat datang, <?php echo $_SESSION['username']; ?></h1>
- <p>Ini adalah halaman admin.</p>
- <a href="/act5/no3/logout.php">Logout</a>
- </body>
- </html>
- ---------------------------------------------//index.php--------------------------------
- <!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.0">
- <title>Faris Rasyid | 50421483</title>
- </head>
- <body>
- <h1>Halaman Login</h1>
- <?php
- session_start();
- if (isset($_SESSION['error_message'])) {
- echo '<p style="color: red;">' . $_SESSION['error_message'] . '</p>';
- unset($_SESSION['error_message']); // Menghapus pesan error setelah ditampilkan
- }
- ?>
- <form action="login.php" method="POST">
- <label for="username">Username:</label>
- <input type="text" id="username" name="username" required><br><br>
- <label for="password">Password:</label>
- <input type="password" id="password" name="password" required><br><br>
- <input type="submit" value="Login">
- </form>
- </body>
- </html>
- ------------------------------------//Login.php-------------------------------
- <?php
- // Simpan informasi login di sini
- $valid_username = 'faris';
- $valid_password = 'admin';
- session_start();
- // Mengecek apakah ada data yang dikirim melalui metode POST
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- $username = $_POST['username'];
- $password = $_POST['password'];
- if ($username == $valid_username && $password == $valid_password) {
- $_SESSION['username'] = $username;
- header('Location: /act5/no3/admin.php');
- exit;
- } else {
- $_SESSION['error_message'] = 'Username atau password salah';
- header('Location: /act5/no3/index.php');
- exit;
- }
- }
- -----------------------------------//logout.php----------------------------------
- <?php
- session_start();
- // Hapus sesi username
- unset($_SESSION['username']);
- // Redirect ke halaman login
- header('Location: /act5/no3/index.php');
- exit;
- -----------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement