Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // checklogin.php
- // version 1.0
- // Generation Time: 19/3/14
- // Server version: 5.6.11 MySQL Community Server (GPL)
- // PHP Version: 5.5.3
- // Database: `user_logon`
- // --------------------------------------------------
- // This file allows a user to submit username and password.
- // This file also establishes a connection to MySQL,
- // checks whether the username/password combination is in the database.
- // If exists, will redirect to login_success.php
- // --------------------------------------------------
- ob_start();
- $host="localhost"; // Host name
- $username="root"; // Mysql username
- $password=""; // Mysql password
- $db_name="UserData"; // Database name
- $tbl_name="Users"; // Table name
- // Connect to server and select database.
- //conection:
- $con = mysqli_connect("$host", "$username")or die("cannot connect");
- mysqli_select_db($con, "$db_name")or die("cannot select DB");
- // This defines $myusername and $mypassword
- $myusername=$_POST['myusername'];
- $mypassword=$_POST['mypassword'];
- // Create the SQL query and run the query using mysqli_query()
- $sql="SELECT * FROM Users WHERE username='$myusername' and password=SHA1('$mypassword')";
- $result=mysqli_query($con, $sql);
- // Mysql_num_row is counting table row
- $count=mysqli_num_rows($result);
- echo $count;
- $counter =0;
- $contents = file_get_contents('statistics.txt');
- // If result matched $myusername and $mypassword, table row must be 1 row
- if($count==1){($counter++ );
- // Redirect to file "login_success.php" if the username and password match
- header("Location:login_success.php");
- $total = $counter + $contents;
- $file = fopen("statistics.txt", "w")or die("unable to open file.");
- fwrite($file, "$total");
- fclose($file);
- }
- else {
- echo "Wrong Username or Password";
- $ErrorText = "Wrong username or password";
- $Date = " @" . date("d-m-y//h:i:sa");
- $myFile = "ErrorLog.txt"; //names the text file
- $fh = fopen($myFile, 'a') or die("can't open file");//Opens a connection to the file
- $stringData = $myusername.", ".$mypassword.", ".$ErrorText. $Date.PHP_EOL;
- fwrite($fh, $stringData);//Writes $stringData to the text file
- fclose($fh);
- //Write to txt files using $myusername and $mypassword
- }
- ob_end_flush();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement