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.

179 lines
5.2 KiB

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