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.

139 lines
3.8 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
  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 = $db->escapeString(
  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 = $db->escapeString(
  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. $r3 = $db->querySingle($q3, true);
  30. if($r3) //not empty
  31. {
  32. $firstName = $r3['first_name'];
  33. $q2 = "select * from users where user_name =
  34. '$i_username' and pass ='" . SHA1($i_password
  35. . $firstName) . "'";
  36. $r2 = $db->querySingle($q2, true);
  37. if($r2)
  38. {
  39. $_SESSION['use'] = true;
  40. $_SESSION['fname'] = $firstName;
  41. $_SESSION['user_id'] = $r2['user_id'];
  42. $_SESSION['username'] = $r2['user_name'];
  43. $_SESSION['agent'] = md5($_SERVER['HTTP_USERAGENT'] . 'salt');
  44. if($dir == 2)
  45. header("Location: ../index.php");
  46. else
  47. header("Location: index.php");
  48. }
  49. else
  50. {
  51. $errors['password'] = "You entered an invalid password";
  52. }
  53. }
  54. else
  55. {
  56. $errors['user'] = "You entered an invalid user name!";
  57. }
  58. }
  59. }
  60. echo '<h1 class="w3-text-teal">';
  61. echo '<center>';
  62. if($loggedIn)
  63. echo 'Profile';
  64. else
  65. echo 'Log In';
  66. echo '</center></h1>';
  67. echo '<div class ="w3-card-4 w3-container w3-padding-16">';
  68. if($loggedIn)
  69. {
  70. echo '<h3 class="w3-center">Welcome ' . $_SESSION['fname'] . '</h3>';
  71. if($dir == 2)
  72. {
  73. echo '<form action="../index.php" method ="post">
  74. <input class="w3-padding-16 w3-hover-dark-grey
  75. w3-btn-block w3-center-align" type="submit" name ="logout"
  76. value="logout" />
  77. <input type="hidden" name="logout" value="TRUE" />
  78. </form>';
  79. }
  80. else
  81. {
  82. echo '<form action="index.php" method ="post">
  83. <input class="w3-padding-16 w3-hover-dark-grey w3-btn-block
  84. w3-center-align" type="submit" name ="logout" value="logout" />
  85. <input type="hidden" name="logout" value="TRUE" />
  86. </form>';
  87. }
  88. }
  89. else
  90. {
  91. if($dir == 2)
  92. echo '<form action ="../index.php" method ="post">';
  93. else
  94. echo '<form action ="index.php" method ="post">';
  95. echo '
  96. <div class="w3-group">
  97. <input class="w3-input" type="text" value="" name="user_name"
  98. class="w3-container w3-card-4" required/>
  99. <label class="w3-label w3-validate">User Name</label>
  100. </div>
  101. <div class="w3-group">
  102. <input class="w3-input" type="password" value="" name="password"
  103. class="w3-container w3-card-4" required/>
  104. <label class="w3-label w3-validate">Password</label>
  105. </div>
  106. <input type="submit" name="login" value="login"
  107. class="w3-padding-16 w3-hover-dark-grey w3-btn-block w3-center-align"/>
  108. <input type="hidden" name="log_in" value="TRUE"/>
  109. </form>';
  110. }
  111. foreach($errors as $msg)
  112. echo " - $msg<br />";
  113. echo '</div>';