A simple php website which displays quotes on pictures of pandas.
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.

145 lines
3.6 KiB

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