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.

143 lines
4.3 KiB

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