Guest User

Untitled

a guest
Jul 6th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. <?php
  2.  
  3. if (isset($_POST['username'])&&isset($_POST['password'])) {
  4.  
  5. $username = $_POST['username'];
  6. $password = $_POST['password'];
  7. $password_hash = md5($password);
  8.  
  9. if (!empty($username)&&!empty($password)) {
  10.  
  11. $query = "SELECT `id` FROM `users` WHERE `username`='".mysql_real_escape_string($username)."' AND `password`='".mysql_real_escape_string($password_hash)."'";
  12. if ($query_run = mysql_query($query)) {
  13. $query_num_rows = mysql_num_rows($query_run);
  14.  
  15. if ($query_num_rows==0) {
  16. echo 'Invalid Username/Password Combination.';
  17. } else if($query_num_rows==1) {
  18. $user_id = mysql_result($query_run, 0, 'id');
  19. $_SESSION['user_id']=$user_id;
  20. header('Location: index.php');
  21. }
  22. }
  23.  
  24. } else {
  25. echo 'Please supply a username and password.';
  26.  
  27. }
  28. }
  29.  
  30. ?>
  31.  
  32. <form action="<?php $current_file; ?>" method="POST">
  33. Username: <input type="text" name="username"><br>
  34. Password: <input type="password" name="password"><br>
  35. <input type="submit" value="Log in">
  36. </form>
Add Comment
Please, Sign In to add comment