Simple website with some JavaScript games.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
4.1 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. <?php
  2. $errors = array();
  3. if(isset($_POST['logout']))
  4. {
  5. $_SESSION = array();
  6. echo '<h3>You are now logged out</h3>';
  7. if($dir == 2)
  8. header("Location: ../index.php");
  9. else
  10. header("Location: index.php");
  11. }
  12. if(isset($_POST['log_in']))
  13. {
  14. //echo 'Login procces';
  15. if(isset($_POST['user_name']))
  16. $i_username = @mysqli_real_escape_string($dbc,
  17. trim($_POST['user_name']));
  18. else
  19. $errors['User Name'] = 'You need to enter a user name!';
  20. if(isset($_POST['password']))
  21. $i_password = @mysqli_real_escape_string($dbc,
  22. trim($_POST['password']));
  23. else
  24. $errors['password'] = "You need to enter a password!";
  25. if($i_password && $i_username)
  26. {
  27. //valid username
  28. $q3 = "select * from users where user_name='$i_username'";
  29. //echo $q3;
  30. $r3 = mysqli_query($dbc, $q3);
  31. if(@mysqli_num_rows($r3) == 1)
  32. {
  33. //echo 'das good';
  34. $firstName = "";
  35. while($row = mysqli_fetch_array($r3))
  36. $firstName = $row['first_name'];
  37. $q2 = "select * from users where user_name =
  38. '$i_username' and pass ='" . SHA1($i_password
  39. . $firstName) . "'";
  40. $r2 = mysqli_query($dbc, $q2);
  41. if(@mysqli_num_rows($r2) == 1)
  42. {
  43. while($row = mysqli_fetch_array($r2))
  44. {
  45. $_SESSION['use'] = true;
  46. $_SESSION['fname'] = $firstName;
  47. $_SESSION['user_id'] = $row['user_id'];
  48. $_SESSION['username'] = $row['user_name'];
  49. $_SESSION['agent'] = md5($_SERVER['HTTP_USERAGENT']
  50. . 'salt');
  51. if($dir == 2)
  52. header("Location: ../index.php");
  53. else
  54. header("Location: index.php");
  55. }
  56. }
  57. else
  58. {
  59. $errors['password'] = "You entered an invalid password";
  60. }
  61. }
  62. else
  63. {
  64. $errors['user'] = "You entered an invalid user name!";
  65. }
  66. }
  67. }
  68. echo '<h1 class="w3-text-teal">';
  69. echo '<center>';
  70. if($loggedIn)
  71. echo 'Profile';
  72. else
  73. echo 'Log In';
  74. echo '</center></h1>';
  75. echo '<div class ="w3-card-4 w3-container w3-padding-16">';
  76. if($loggedIn)
  77. {
  78. echo '<h3 class="w3-center">Welcome ' . $_SESSION['fname'] . '</h3>';
  79. if($dir == 2)
  80. {
  81. echo '<form action="../index.php" method ="post">
  82. <input class="w3-padding-16 w3-hover-dark-grey
  83. w3-btn-block w3-center-align" type="submit" name ="logout"
  84. value="logout" />
  85. <input type="hidden" name="logout" value="TRUE" />
  86. </form>';
  87. }
  88. else
  89. {
  90. echo '<form action="index.php" method ="post">
  91. <input class="w3-padding-16 w3-hover-dark-grey w3-btn-block
  92. w3-center-align" type="submit" name ="logout" value="logout" />
  93. <input type="hidden" name="logout" value="TRUE" />
  94. </form>';
  95. }
  96. }
  97. else
  98. {
  99. if($dir == 2)
  100. echo '<form action ="../index.php" method ="post">';
  101. else
  102. echo '<form action ="index.php" method ="post">';
  103. echo '
  104. <div class="w3-group">
  105. <input class="w3-input" type="text" value="" name="user_name"
  106. class="w3-container w3-card-4" required/>
  107. <label class="w3-label w3-validate">User Name</label>
  108. </div>
  109. <div class="w3-group">
  110. <input class="w3-input" type="password" value="" name="password"
  111. class="w3-container w3-card-4" required/>
  112. <label class="w3-label w3-validate">Password</label>
  113. </div>
  114. <input type="submit" name="login" value="login"
  115. class="w3-padding-16 w3-hover-dark-grey w3-btn-block w3-center-align"/>
  116. <input type="hidden" name="log_in" value="TRUE"/>
  117. </form>';
  118. }
  119. foreach($errors as $msg)
  120. echo " - $msg<br />";
  121. echo '</div>';