Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <meta charset="utf-8">
- <title>Laikin Games</title>
- <link rel="stylesheet" type="text/css" href="stylesheet.css">
- <link href="https://fonts.googleapis.com/css?family=Krub" rel="stylesheet">
- <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
- <link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
- <script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
- <link href="https://fonts.googleapis.com/css?family=Noto+Sans" rel="stylesheet">
- <style>
- body {
- text-decoration: none;
- }
- </style>
- </head>
- <body onload="startTime()" >
- <?php
- $user = $_POST['user']; // input variable
- $pass = $_POST['pass']; // input variable
- $userreg = $_POST['userreg']; // input variable
- $passreg = $_POST['passreg']; // input variable
- $servername = "localhost"; // line 37-40 is logging into sql
- $username = "Stu449";
- $password = "Stu2515!";
- $dbname = "stu449";
- $conn = new mysqli($servername,$username,$password,$dbname); // checking the connection
- if ($conn->connect_error) { // if the connection cant be found display error
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "UPDATE hitcounter SET hits = hits + 1 WHERE ID = 2";
- $conn->query($sql);
- session_start(); // starting the session
- ?>
- <div class="container">
- <div class="box">
- <h1 font-family: 'Noto Sans', sans-serif;''>Laikin Games</h1>
- <?php
- if ($_SESSION['loggedIn'] == true) { // if you're logged in go to the main page
- header ("location: main.php"); // redirects to login.php
- }
- if ($_POST['submit']) { // when submit is pressed
- if ($userreg !="" && $passreg!="") {
- $sql = "INSERT INTO accounts (username, password) VALUES ('$userreg', '$passreg')"; // insert the text input to the table
- if ($conn->query($sql) === TRUE) { // checking if the query was succesful
- echo "New accounts created, please login" . "<br />";
- }
- else {
- // Failed
- echo "Error: " . $sql . "<br>" . $conn->error;
- }
- }
- $command = "SELECT * FROM accounts WHERE username='$user'"; // sql to execute
- $res = $conn->query($command); // response
- if ($res->num_rows > 0) { // if there are more than 0 rows
- while ($row = $res->fetch_assoc()) { // loop through every row
- if ($pass == $row['password']) {
- // logged in
- $_SESSION['loggedIn'] = true;
- $_SESSION['loggedinuser'] = $user;
- header ("location: main.php"); // redirect to main.php
- }else {
- // not
- $_SESSION['loggedIn'] = false;
- }
- }
- }
- }
- $log_file = 'login_log.txt'; // creating the log file
- $file = fopen("login_log.txt","a"); // assigning the variable for opening the log file
- ?>
- <h4>Please login to go further</h4>
- <form action="login.php" method="POST">
- <p>Use the admin details if you don't want to make an account admin:password</p>
- <div class="mdl-textfield mdl-js-textfield">
- <input type="text" class="mdl-textfield__input" required placeholder="Username" name="user">
- <input type="password" class="mdl-textfield__input" required placeholder="Password" name="pass">
- <br />
- <input type="submit" name="submit">
- </div>
- </form>
- <h4>If you don't have an account please register one</h4>
- <form action="login.php" method="POST">
- <div class="mdl-textfield mdl-js-textfield">
- <input type="text" class="mdl-textfield__input" required placeholder="Username" name="userreg">
- <input type="password" class="mdl-textfield__input" required placeholder="Password" name="passreg">
- <br />
- <input type="submit" name="submit" value="Register">
- </div>
- </form>
- <br />
- <a style="text-decoration: none;font-size:30px;" href="index.php"> Home | </a>
- <a style="text-decoration: none;font-size:30px;"href="login_log.txt">Login Log</a>
- </div>
- </div>
- </div>
- <?php
- if (isset($_POST["submit"])){
- if ($user !="" && $pass!="") {
- if ($_SESSION['loggedIn'] == true) {
- $logtext = $user . ":" . $pass . " Date: " . date("d/m/Y") . " IP: " . $_SERVER['REMOTE_ADDR'] . " Login Successful" . "\n";
- fwrite($file,$logtext);
- fclose($file);
- }
- else {
- $logtext = $user . ":" . $pass . " Date: " . date("d/m/Y") . " IP: " . $_SERVER['REMOTE_ADDR'] . " Incorrect Details" . "\n";
- fwrite($file,$logtext);
- fclose($file);
- }
- }
- if ($userreg !="" && $passreg!="") {
- $logtext = $userreg . ":" . $passreg . " Date: " . date("d/m/Y") . " IP: " . $_SERVER['REMOTE_ADDR'] . " Account Created" . "\n";
- fwrite($file,$logtext);
- fclose($file);
- }
- }
- $conn->close;
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement