Skip to content

Commit

Permalink
Pertemuan 9 - Praktikum 10
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Apr 17, 2024
1 parent ff2412a commit 22e88cc
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pertemuan9/homeSession.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php

session_start();

if ($_SESSION['status'] == 'login') {
echo "Selamat datang " . $_SESSION['username'];
?>
<br><a href="sessionLogout.php">Log out</a>
<?php
} else {
echo "Anda belum login silakan " ?>
<a href="sessionLoginForm.html">Log in</a>
<?php
}


?>
</body>
</html>
28 changes: 28 additions & 0 deletions pertemuan9/sessionLoginForm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>

<form action="sessionLoginProses.php" method="post">
<table>
<tr>
<td>Username</td>
<td><input type="text" name="username" size="20"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" size="20"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Login" value="Log in"></td>
</tr>
</table>
</form>

</body>
</html>
30 changes: 30 additions & 0 deletions pertemuan9/sessionLoginProses.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

include "koneksi.php";

$username = $_POST['username'];
$password = md5($_POST['password']);


$query = "SELECT * FROM user WHERE username = '$username' and password = '$password'";
$result = mysqli_query($connect, $query);
$cek = mysqli_num_rows($result);

if ($cek > 0) {
session_start();
$_SESSION['username'] = $username;
$_SESSION['status'] = 'login';
?>
Anda berhasil login, silakan menuju
<a href="homeSession.php">Halaman Home</a>

<?php
} else {
?>
Gagal login, silakan login lagi
<a href="sessionLoginForm.html">Halaman Login</a>
<?php
}


?>
9 changes: 9 additions & 0 deletions pertemuan9/sessionLogout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

session_start();
session_destroy();

echo "Anda berhasil logout";


?>

0 comments on commit 22e88cc

Please sign in to comment.