CODINGAN WEB LOGIN DAN LOGOUT
Tutorial membuat Coding login dan logout
1.CODINGAN LOGIN
<?php
session_start();
if (isset($_SESSION['username']) || !empty($_SESSION['username'])) {
header("location:blog.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>LOGIN</title>
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=device-width , initial-scale=1">
</head>
<body>
<div id="login">
<div class="center">
<h2>LOGIN</h2>
<form class="f1" action="" method="post">
<input class="itpw" type="text" name="username" placeholder="Username or Email"><br>
<input class="itpw" type="text" name="password" placeholder="password"><br>
<input class="its" type="submit" name="login" value="Login"><br>
<!--proses login-->
<?php
if(isset($_POST['login'])){
$username = $_POST['username'];
$filter = mysql_real_escape_string(stripslashes(strip_tags(htmlspecialchars($_POST['username'], ENT_QUOTES ))));
$password = md5($_POST['password']);
$user = 'admin1';
$key = md5('admin');
if(( !empty($username)&&!empty($password))){
if($username == $user && $password == $key){
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
//alihkan ke menu utama
header("location:blog.php");
echo "<p style='color:red;font-size13px;margin:2px auto;'> (*) Username atau password salah. </p>";
}
} else {
echo "<p style='color:red;font-size13px;margin:2px auto;'> (*) Silahakan isi form yang tersedia. </p>";
}
}
?>
</form>
<p> <a href="#">forget your password ? </a> | <a href="#">create account</a> </p>
</div>
</div>
</body>
</html>
Tampilan login
2.CODINGAN LOGOUT
<?php
//menghapus session
session_start();
$_SESSION['username']=' ';
unset($_SESSION['username']);
session_unset();
session_destroy();
header("location:index.php");
?>
Tampilan Logout
Tampilan Logout
Komentar
Posting Komentar