Guest User

Process.php script

a guest
Mar 13th, 2017
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.  
  5. <style type="text/css">
  6.  
  7. </style>
  8. <title></title>
  9. </head>
  10. <body>
  11.  
  12. <?php
  13.  
  14.  
  15.  
  16.  
  17. $servername = "localhost"; //indicates which server to connect to
  18. $db = "assignment"; //indicates which db to access
  19. $username = "usertblOne"; //indicates which user to connect to, this depends on the db
  20. $password = "root123"; //password for the user above
  21.  
  22. $userName = $_POST['userName']; //collects the post data from the userName box
  23. $userPass = $_POST['userPass']; //collects the post data from the userPass password box
  24.  
  25. $conn = new mysqli($servername, $username, $password, $db); //stores the connection to the database
  26.  
  27. if($conn->connect_error){ //run a check on whether an error occurs or not
  28. die("Connection Failed: " . $conn->connect_error); //print the error out
  29. }
  30.  
  31.  
  32. $query="SELECT * FROM users WHERE username='$userName' and password='$userPass'"; //stores the SQL that we will execute later
  33. $result = $conn->query($query); //store the result of the query and at the same time, executing the query.
  34. $rowCount = $result->num_rows; //storing the amount of rows that the SELECT has found
  35.  
  36. if ($rowCount > 0){ //if rowcount is greater than 0, means there was a result found in the database
  37. // Successful Login
  38. session_start();
  39. $_SESSION['lgnSuccess'] = array("Login confirmed");
  40.  
  41. include('webstats.php');
  42. header('Location: ../blog/index.php'); //Takes user to the next stage of this php project - the main page of the blog
  43.  
  44.  
  45. }else{
  46.  
  47. $date = date("jS \of F Y h:i:s A");
  48.  
  49. $myfile = fopen("ErrorLog.txt", "a");
  50. fwrite($myfile, $date . " " . "Login attempt failure on user: " . $userName .PHP_EOL);
  51. fclose($myfile);
  52.  
  53. session_start(); //open up a session
  54.  
  55. $_SESSION['errors'] = array("Your username or password was incorrect."); //create a session and call it errors
  56.  
  57. header('Location: ./index.php'); //returns user to the original login page.
  58.  
  59. // Unsuccessful Login
  60. }
  61.  
  62.  
  63.  
  64. ?>
  65.  
  66. </body>
  67. </html>
Add Comment
Please, Sign In to add comment