Source Code PHP Form Login yang Memiliki Fitur Remember Me Menggunakan Cookie

Friday, May 15, 20150 comments

Di bawah ini adalah contoh program dasar pemakaian cookie pada form login yang memiliki fitur Remember Me. Semoga bermanfaat.

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";
}
?>
Share this article :

Post a Comment

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Tutorial Web Programming - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger