Guest User

Untitled

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