Advertisement
Guest User

checklogin.php

a guest
Jun 26th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 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="UserData"; // Database name
  20. $tbl_name="Users"; // 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. // This defines $myusername and $mypassword
  30. $myusername=$_POST['myusername'];
  31. $mypassword=$_POST['mypassword'];
  32.  
  33.  
  34. // Create the SQL query and run the query using mysqli_query()
  35. $sql="SELECT * FROM Users WHERE username='$myusername' and password=SHA1('$mypassword')";
  36. $result=mysqli_query($con, $sql);
  37.  
  38.  
  39. // Mysql_num_row is counting table row
  40. $count=mysqli_num_rows($result);
  41. echo $count;
  42.  
  43. $counter =0;
  44. $contents = file_get_contents('statistics.txt');
  45. // If result matched $myusername and $mypassword, table row must be 1 row
  46.  
  47. if($count==1){($counter++ );
  48. // Redirect to file "login_success.php" if the username and password match
  49. header("Location:login_success.php");
  50.  
  51. $total = $counter + $contents;
  52.  
  53. $file = fopen("statistics.txt", "w")or die("unable to open file.");
  54. fwrite($file, "$total");
  55. fclose($file);
  56.  
  57. }
  58. else {
  59. echo "Wrong Username or Password";
  60.  
  61. $ErrorText = "Wrong username or password";
  62. $Date = " @" . date("d-m-y//h:i:sa");
  63. $myFile = "ErrorLog.txt"; //names the text file
  64. $fh = fopen($myFile, 'a') or die("can't open file");//Opens a connection to the file
  65. $stringData = $myusername.", ".$mypassword.", ".$ErrorText. $Date.PHP_EOL;
  66. fwrite($fh, $stringData);//Writes $stringData to the text file
  67. fclose($fh);
  68.  
  69. //Write to txt files using $myusername and $mypassword
  70. }
  71.  
  72. ob_end_flush();
  73. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement