Guest User

Untitled

a guest
Mar 16th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. if(isset($_POST['login'])) {
  2. $username = mysqli_real_escape_string($db, $_POST['username']);
  3. $password = mysqli_real_escape_string($db, $_POST['password']);
  4.  
  5. // Ensure that form fields are filled properly
  6. if(empty($username)) {
  7. array_push($errors, "Username is required!");
  8. }
  9.  
  10. if(empty($password)) {
  11. array_push($errors, "Password is required!");
  12. }
  13. if(count($errors) == 0){
  14. $password = md5($password); // Encrypt password before comparing this one with the one in database
  15. $query = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";
  16. $result = mysqli_query($db, $query);
  17. if (mysqli_num_rows($result) == 1) {
  18. $_SESSION['username'] = $username;
  19. $_SESSION['success'] = "You are now logged in";
  20. header('location: ../system.php'); // Redirect to main page location
  21. } else {
  22. array_push($errors, "Wrong username/password combination");
  23. header('location: ../php/login.php');
  24. }
  25. }
  26. }
Add Comment
Please, Sign In to add comment