Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. <?php
  2.  
  3. if(isset($_POST["username"])) {
  4. $username = $_POST["username"];
  5.  
  6. $pass = $_POST["password"];
  7. $validated = false;
  8. }else{
  9. $username= "";
  10. $pass ="";
  11. }
  12. // When the log in as be clieck it will start the session on
  13. session_start();
  14. $_SESSION['login'] ="";
  15. $_SESSION['Username'] = "";
  16. $_SESSION['pass'] = "";
  17. $_SESSION['id'] = "";
  18. if($username!="" && $pass!=""){
  19. //This is connecting to the databse by finding the database and using the log in details to get onto the database.
  20. $connect = mysqli_connect("localhost", "root", "root", "c9") or die("summut gungan rong");
  21. $result = $connect->query("SELECT * FROM `users` WHERE `Username` = '$username' AND `Password` = '$pass'");
  22. $noRows = $result->num_rows;
  23. $error = fopen("error.txt","a") or exit ("cant open the file");
  24. $usernamesID = $result->fetch_assoc();
  25. $_SESSION["id"] = $usernamesID['id'];
  26.  
  27. //This is checking to see if the username and password was correct, if it is correct it will to the protect site.
  28. if($result > 0){$validated = true;}
  29. if($validated){
  30. $_SESSION['login'] = "That GRRRRREAT";
  31. $_SESSION['Username'] = $username;
  32. $_SESSION['password'] = $pass;
  33. header('Location: profilepage.php');
  34. }else{
  35. $_SESSION['login'] = "";
  36. echo "<p>Your Error has been Logged</p>";
  37. //When the user has failed to log in it will log it onto the error text file, this is make sure that it will show what the user has tried so it can prevent anyone for guessing the usernames/passwords.
  38. fwrite ($error, "\n The Username is : " . $_POST['username']. "\n The password is:" . $_POST['password'] . "\n\n");
  39. echo " Sorry you have put in the wrong information.";
  40. }
  41. }else{$_SESSION['login'] = "";}
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement