Advertisement
Guest User

Check Login.php

a guest
Jun 21st, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. <?php
  2. // checklogin.php
  3. // version 1.0
  4. // Generation Time: 19/3/14
  5. // Server version: 5.6.11 MySQL Community Server (GPL)
  6. // PHP Version: 5.5.3
  7. // Database: `user_logon`
  8. // --------------------------------------------------
  9. // This file allows a user to submit username and password.
  10. // This file also establishes a connection to MySQL,
  11. // checks whether the username/password combination is in the database.
  12. // If exists, will redirect to login_success.php
  13. // --------------------------------------------------
  14.  
  15. ob_start();
  16. $host="localhost"; // Host name
  17. $username="root"; // Mysql username
  18. $password=""; // Mysql password
  19. $db_name="user_login"; // Database name
  20. $tbl_name="members"; // Table name
  21.  
  22.  
  23. // Connect to server and select database.
  24. //conection:
  25. $con = mysqli_connect("$host", "$username")or die("cannot connect");
  26. mysqli_select_db($con, "$db_name")or die("cannot select DB");
  27.  
  28.  
  29. // Define $myusername and $mypassword
  30. $myEmail=$_POST['UsernameInput'];
  31. $mypassword=$_POST['passwordInput'];
  32. $date = (new DateTime())->setTimeZone(new DateTimeZone('Europe/London'))->format('d-m-Y H:i:s');
  33. $browser = $_SERVER ['HTTP_USER_AGENT'];
  34. $IP = $_SERVER ['REMOTE_ADDR'];
  35. $filler = " ";
  36. // Create the SQL query and run the query using mysqli_query()
  37. $sql="SELECT * FROM members WHERE username='$myEmail' and password=SHA1('$mypassword')";
  38. $result=mysqli_query($con, $sql);
  39.  
  40.  
  41. // Mysql_num_row is counting table row
  42. $count=mysqli_num_rows($result);
  43.  
  44. // If result matched $myusername and $mypassword, table row must be 1 row
  45. $counter =0;
  46. $contents = file_get_contents('statistics.txt');
  47. if($count==1){ ($counter++ );
  48. $total = $counter + $contents;
  49.  
  50. header("Location:contentManagement.php");
  51.  
  52. $file = fopen("statistics.txt", "w")or die("unable to open file.");
  53. fwrite($file, "$total");
  54. fclose($file);
  55.  
  56.  
  57.  
  58. }
  59. else {
  60. echo "Wrong Username or Password";
  61. $myfile = fopen("ErrorLog.txt", "a") or die("unable to open file!");
  62. //$txt = "Username$myEmail,$mypassword,$date".PHP_EOL;
  63. fwrite($myfile, "Username: "."$myEmail".PHP_EOL);
  64. fwrite($myfile, "Password: "."$mypassword".PHP_EOL);
  65. fwrite($myfile, "Date & Time: "."$date".PHP_EOL);
  66. fwrite($myfile, "Browser: "."$browser".PHP_EOL);
  67. fwrite($myfile, "IP address: "."$IP".PHP_EOL);
  68. fwrite($myfile, "$filler".PHP_EOL);
  69. fclose($myfile);
  70. }
  71.  
  72. ob_end_flush();
  73.  
  74.  
  75.  
  76.  
  77. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement