Anda di halaman 1dari 3

MEMBUAT SESSION

1. MEMBUAT HALAMAN INDEX.PHP

<?php include "cek-login.php"; ?>

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>Untitled Document</title>

</head>

<body>

<h2>Ini halaman berhasil login (index.php)

</h2>

<h1><a href="keluar.php">Logout</a></h1>

</body>

</html>

2. MEMBUAT HALAMAN cek-login.php


<?php
session_start();
if(!isset($_SESSION['user'])){
header("location:loginForm.php");
}
?>
3. Membuat halaman formLogin.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<link rel="stylesheet" href="login.css">
<style>
#er{
color:#FF0004;
}
</style>
</head>
<body>
<div id="ok">
<div id="tahu">
<h1><font color="#FFA600">SMK Babussalam</font><font color="#FFFD00">
Login</font></h1>
<form id="form1" name="form1" method="post" action="proseslog.php">
<table width="100%" border="0">
<tbody>
<tr>
<td>Username</td>
<td><input type="text" name="username" id="username" class="txt"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" id="password" class="txt"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="submit" id="submit" value="Submit"></td>
</tr>
</tbody>
</table>
</form>
<?php
if(isset($_GET['error'])==1){
echo "<h2 id='er'> Sorry Coy login salah </h2>";
}
?>
</div>
</div>
</body>
</html>
4. Membuat halaman prosesLogin.php
<?php

session_start();
include "db.php"; //inlcude akan mengambil seluruh isi dari dokumen db.php
//kita tampung name dari inputan yakni username dan password
$user=$_POST['username'];
$pas=md5($_POST['password']);
//lakukan pengambilan data dari database
//$melon=mysqli_query($dbs,"select * from admin where username='$user' and
password='$pas'");
//if(mysqli_num_rows($melon)==1){
if($user=="kucing" and $pas="meong"){
$_SESSION['user']=$user;
header("location:index.php");
}else{//jika username dan password salah
header("location:loginForm.php?error=1");
}
?>

Anda mungkin juga menyukai