Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.86 KB | None | 0 0
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <title>Laikin Games</title>
  5. <link rel="stylesheet" type="text/css" href="stylesheet.css">
  6. <link href="https://fonts.googleapis.com/css?family=Krub" rel="stylesheet">
  7. <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
  8. <link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
  9. <script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
  10. <link href="https://fonts.googleapis.com/css?family=Noto+Sans" rel="stylesheet">
  11.  
  12. <style>
  13. body {
  14. text-decoration: none;
  15.  
  16. }
  17. </style>
  18. </head>
  19. <body onload="startTime()" >
  20. <?php
  21. $user = $_POST['user']; // input variable
  22. $pass = $_POST['pass']; // input variable
  23. $userreg = $_POST['userreg']; // input variable
  24. $passreg = $_POST['passreg']; // input variable
  25.  
  26. $servername = "localhost"; // line 37-40 is logging into sql
  27. $username = "Stu449";
  28. $password = "Stu2515!";
  29. $dbname = "stu449";
  30. $conn = new mysqli($servername,$username,$password,$dbname); // checking the connection
  31. if ($conn->connect_error) { // if the connection cant be found display error
  32. die("Connection failed: " . $conn->connect_error);
  33.  
  34. }
  35.  
  36.  
  37.  
  38. $sql = "UPDATE hitcounter SET hits = hits + 1 WHERE ID = 2";
  39. $conn->query($sql);
  40.  
  41. session_start(); // starting the session
  42. ?>
  43.  
  44.  
  45.  
  46. <div class="container">
  47. <div class="box">
  48. <h1 font-family: 'Noto Sans', sans-serif;''>Laikin Games</h1>
  49.  
  50. <?php
  51.  
  52. if ($_SESSION['loggedIn'] == true) { // if you're logged in go to the main page
  53. header ("location: main.php"); // redirects to login.php
  54. }
  55. if ($_POST['submit']) { // when submit is pressed
  56.  
  57.  
  58.  
  59. if ($userreg !="" && $passreg!="") {
  60. $sql = "INSERT INTO accounts (username, password) VALUES ('$userreg', '$passreg')"; // insert the text input to the table
  61.  
  62. if ($conn->query($sql) === TRUE) { // checking if the query was succesful
  63.  
  64. echo "New accounts created, please login" . "<br />";
  65. }
  66. else {
  67. // Failed
  68. echo "Error: " . $sql . "<br>" . $conn->error;
  69. }
  70.  
  71. }
  72.  
  73. $command = "SELECT * FROM accounts WHERE username='$user'"; // sql to execute
  74.  
  75. $res = $conn->query($command); // response
  76.  
  77. if ($res->num_rows > 0) { // if there are more than 0 rows
  78. while ($row = $res->fetch_assoc()) { // loop through every row
  79. if ($pass == $row['password']) {
  80. // logged in
  81. $_SESSION['loggedIn'] = true;
  82. $_SESSION['loggedinuser'] = $user;
  83. header ("location: main.php"); // redirect to main.php
  84.  
  85. }else {
  86. // not
  87. $_SESSION['loggedIn'] = false;
  88. }
  89.  
  90.  
  91. }
  92. }
  93.  
  94.  
  95. }
  96.  
  97.  
  98. $log_file = 'login_log.txt'; // creating the log file
  99. $file = fopen("login_log.txt","a"); // assigning the variable for opening the log file
  100.  
  101.  
  102.  
  103. ?>
  104. <h4>Please login to go further</h4>
  105. <form action="login.php" method="POST">
  106. <p>Use the admin details if you don't want to make an account admin:password</p>
  107. <div class="mdl-textfield mdl-js-textfield">
  108. <input type="text" class="mdl-textfield__input" required placeholder="Username" name="user">
  109. <input type="password" class="mdl-textfield__input" required placeholder="Password" name="pass">
  110. <br />
  111. <input type="submit" name="submit">
  112. </div>
  113.  
  114. </form>
  115. <h4>If you don't have an account please register one</h4>
  116. <form action="login.php" method="POST">
  117. <div class="mdl-textfield mdl-js-textfield">
  118. <input type="text" class="mdl-textfield__input" required placeholder="Username" name="userreg">
  119. <input type="password" class="mdl-textfield__input" required placeholder="Password" name="passreg">
  120. <br />
  121.  
  122. <input type="submit" name="submit" value="Register">
  123. </div>
  124.  
  125. </form>
  126.  
  127. <br />
  128.  
  129. <a style="text-decoration: none;font-size:30px;" href="index.php"> Home | </a>
  130. <a style="text-decoration: none;font-size:30px;"href="login_log.txt">Login Log</a>
  131.  
  132. </div>
  133. </div>
  134. </div>
  135.  
  136. <?php
  137.  
  138. if (isset($_POST["submit"])){
  139. if ($user !="" && $pass!="") {
  140. if ($_SESSION['loggedIn'] == true) {
  141. $logtext = $user . ":" . $pass . " Date: " . date("d/m/Y") . " IP: " . $_SERVER['REMOTE_ADDR'] . " Login Successful" . "\n";
  142. fwrite($file,$logtext);
  143. fclose($file);
  144.  
  145. }
  146. else {
  147. $logtext = $user . ":" . $pass . " Date: " . date("d/m/Y") . " IP: " . $_SERVER['REMOTE_ADDR'] . " Incorrect Details" . "\n";
  148. fwrite($file,$logtext);
  149. fclose($file);
  150. }
  151. }
  152. if ($userreg !="" && $passreg!="") {
  153. $logtext = $userreg . ":" . $passreg . " Date: " . date("d/m/Y") . " IP: " . $_SERVER['REMOTE_ADDR'] . " Account Created" . "\n";
  154. fwrite($file,$logtext);
  155. fclose($file);
  156. }
  157. }
  158.  
  159.  
  160.  
  161. $conn->close;
  162. ?>
  163.  
  164.  
  165.  
  166. </body>
  167. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement