Advertisement
Guest User

login.php

a guest
Feb 17th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. <?php
  2.  
  3. session_start(); //starting session
  4. $error = ''; //variable to store error message
  5.  
  6. if (isset($_POST['submit'])) {
  7.  
  8. if (empty($_POST['username']) || empty($_POST['password'])) {
  9. $error = "Nick i Hasło nie mogą być puste!"; //error empty pwd and nick
  10. }
  11. else {
  12. $username = $_POST['username']; //define username
  13. $password = $_POST['password']; //define password
  14.  
  15. //connect with database
  16. $conn = mysqli_connect("localhost", "00194748_otako", "090909B1", "00194748_otako");
  17.  
  18. //matching password and username with database
  19. $query = "SELECT username, password FROM login WHERE username=? AND password=? LIMIT 1";
  20.  
  21. //security
  22. $stmt = $conn -> prepare($query);
  23. $stmt -> bind_param("ss", $username, $password);
  24. $stmt -> execute();
  25. $stmt -> bind_result($username, $password);
  26. $stmt -> store_result();
  27.  
  28. if ($stmt -> fetch()) {
  29. $_SESSION['login_user'] = $username; //session initializing
  30. header("location: profile.php"); //rediecting to profile page
  31. }
  32. else {
  33. $error = "Nick lub/i Hasło jest/są niepoprawne/niepoprawny";
  34. }
  35. mysqli_close($conn); //closing connection
  36. }
  37. }
  38.  
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement