File logincookie.php :
<?php
if (isset($_COOKIE["nama"]) && isset($_COOKIE["pasw"])){
$nm = $_COOKIE["nama"];
$pw = $_COOKIE["pasw"];
} else {
$nm = "";
$pw = "";
}
?>
<html>
<head><title>Cookie Remember Me</title></head>
<body>
<form action="logincookie2.php" method="get">
Nama <input type="text" name="nm" value="<?php echo($nm); ?>" /><br />
Password <input type="password" name="pw" value="<?php echo($pw); ?>" /><br />
<input type="submit" value="Login" /><br />
<input type="checkbox" name="ingat[]" value="1" />Remember me!<br />
</form>
</body>
</html>
File logincookie2.php :
<?php
if (isset($_GET["nm"]) && isset($_GET["pw"])){
if ($_GET["nm"]=="admin" && $_GET["pw"]=="kosong") {
$ingat = (isset($_GET["ingat"]))?$_GET["ingat"]:null;
if ($ingat[0]=="1") {
setcookie("nama", $_GET["nm"], time()+60*5);
setcookie("pasw", $_GET["pw"], time()+60*5);
} else {
setcookie("nama");
setcookie("pasw");
}
echo "Selamat Datang";
} else {
echo "Login gagal!";
}
} else {
echo "Access denied";
}
?>
Tidak ada komentar:
Posting Komentar