Advertisement
Guest User

index.php

a guest
Mar 6th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. <?php
  2. session_start();
  3. $dbh = new PDO('mysql:host=localhost;dbname=contoh', "root", "");
  4. ?>
  5.  
  6. <form method="POST">
  7. Username: <input type="text" name="username" required=""><br><br>
  8. Password: <input type="password" name="password" required=""><br><br>
  9. <button name="login" type="submit">login</button><br>
  10. </form>
  11.  
  12. <?php
  13. if(isset($_POST['login'])){
  14. $sql= $dbh->query("SELECT * FROM user_demo2 WHERE username='$_POST[username]'") or die(mysqli_error($db));
  15. $login = $sql->fetch();
  16.  
  17. // cek username dan password dengan yang ada di database
  18. if(md5($_POST['password']) == $login['password'] && $_POST['username'] == $login['username']){
  19. // bikin session
  20. $_SESSION['login'] = $_POST['username'];
  21. header("location: admin.php");
  22. }
  23.  
  24. else { ?>
  25. <strong>Maaf:</strong> Kombinasi username dan password salah.
  26. <?php
  27. }
  28.  
  29. }
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement