Advertisement
Guest User

Untitled

a guest
Aug 26th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4.  
  5. if ((!isset($_POST['username'])) || (!isset($_POST['password'])))
  6. {
  7. header('Location: index.php');
  8. exit();
  9. }
  10.  
  11. require_once "connect.php";
  12.  
  13. $connect = @new mysqli($DB_host, $DB_user, $DB_password, $DB_name);
  14.  
  15. if ($connect->connect_errno!=0)
  16. {
  17. echo "Error: ".$connect->connect_errno;
  18. }
  19. else
  20. {
  21. $login = $_POST['username'];
  22. $haslo = $_POST['password'];
  23.  
  24. $login = htmlentities($login, ENT_QUOTES, "UTF-8");
  25.  
  26. if ($rezultat = @$connect->query(
  27. sprintf("SELECT * FROM users WHERE username='%s'",
  28. mysqli_real_escape_string($connect,$login))))
  29. {
  30. $ilu_userow = $rezultat->num_rows;
  31. if($ilu_userow>0)
  32. {
  33. $wiersz = $rezultat->fetch_assoc();
  34.  
  35. if (password_verify($haslo, $wiersz['password']))
  36. {
  37. $_SESSION['zalogowany'] = true;
  38. $_SESSION['id'] = $wiersz['id'];
  39. $_SESSION['username'] = $wiersz['username'];
  40. $_SESSION['auth'] = $wiersz['auth'];
  41. $_SESSION['points'] = $wiersz['points'];
  42. $_SESSION['sukces'] ='<div class="sukces"><i class="fa fa-times"></i> Zalogowano pomyślnie :)</div>';
  43. unset($_SESSION['blad']);
  44. $rezultat->free_result();
  45.  
  46. header('Location: index.php');
  47. }
  48. else
  49. {
  50. unset($_SESSION['sukces']);
  51. $_SESSION['blad'] ='<div class="blad"><i class="fa fa-times"></i> Błędne dane :(</div>';
  52. header('Location: index.php');
  53. }
  54.  
  55. } else {
  56. unset($_SESSION['sukces']);
  57. $_SESSION['blad'] ='<div class="blad"><i class="fa fa-times"></i> Błędne dane :(</div>';
  58. header('Location: index.php');
  59.  
  60. }
  61.  
  62. }
  63.  
  64. $connect->close();
  65. }
  66.  
  67. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement