Advertisement
Guest User

Untitled

a guest
Jul 9th, 2017
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. <?php //Start the Session
  2. session_start();
  3. require('connect.php');
  4. //3. If the form is submitted or not.
  5. //3.1 If the form is submitted
  6. if (isset($_POST['username']) and isset($_POST['password'])){
  7. //3.1.1 Assigning posted values to variables.
  8. $username = $_POST['username'];
  9. $password = $_POST['password'];
  10. //3.1.2 Checking the values are existing in the database or not
  11. $query = "SELECT * FROM user WHERE
  12. username='$username' and password='$password'";
  13. $result = mysqli_query($connection, $query)
  14. or die(mysqli_error($connection));
  15. $count = mysqli_num_rows($result);
  16. //3.1.2 If the posted values are equal to the
  17. //database values, then session will be created
  18. //for the user.
  19. if ($count == 1) { $row = $result-
  20. >fetch_array(MYSQLI_ASSOC);
  21. if (password_verify($password,
  22. $row['password'])) { $_SESSION['username']
  23. = $username;
  24. }
  25. }else{
  26. //3.1.3 If the login credentials doesn't match, he
  27. //will be shown with an error message.
  28. $fmsg = "Invalid Login Credentials.";
  29. }
  30. }
  31. //3.1.4 if the user is logged in Greets the user
  32. //with message
  33. if (isset($_SESSION['username'])){ $username
  34. = $_SESSION['username'];
  35. echo "Hai " . $username . " ";
  36. echo "This is the Members Area ";
  37. echo "<a href='logout.php'>Logout</a>";
  38. }else{
  39. //3.2 When the user visits the page first time,
  40. //simple login form will be displayed. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement