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="user_login"; // Database name
- $tbl_name="members"; // 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");
- // Define $myusername and $mypassword
- $myEmail=$_POST['UsernameInput'];
- $mypassword=$_POST['passwordInput'];
- $date = (new DateTime())->setTimeZone(new DateTimeZone('Europe/London'))->format('d-m-Y H:i:s');
- $browser = $_SERVER ['HTTP_USER_AGENT'];
- $IP = $_SERVER ['REMOTE_ADDR'];
- $filler = " ";
- // Create the SQL query and run the query using mysqli_query()
- $sql="SELECT * FROM members WHERE username='$myEmail' and password=SHA1('$mypassword')";
- $result=mysqli_query($con, $sql);
- // Mysql_num_row is counting table row
- $count=mysqli_num_rows($result);
- // If result matched $myusername and $mypassword, table row must be 1 row
- $counter =0;
- $contents = file_get_contents('statistics.txt');
- if($count==1){ ($counter++ );
- $total = $counter + $contents;
- header("Location:contentManagement.php");
- $file = fopen("statistics.txt", "w")or die("unable to open file.");
- fwrite($file, "$total");
- fclose($file);
- }
- else {
- echo "Wrong Username or Password";
- $myfile = fopen("ErrorLog.txt", "a") or die("unable to open file!");
- //$txt = "Username$myEmail,$mypassword,$date".PHP_EOL;
- fwrite($myfile, "Username: "."$myEmail".PHP_EOL);
- fwrite($myfile, "Password: "."$mypassword".PHP_EOL);
- fwrite($myfile, "Date & Time: "."$date".PHP_EOL);
- fwrite($myfile, "Browser: "."$browser".PHP_EOL);
- fwrite($myfile, "IP address: "."$IP".PHP_EOL);
- fwrite($myfile, "$filler".PHP_EOL);
- fclose($myfile);
- }
- ob_end_flush();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement