"OdenseTrack" is a school assignment/project from AspIT https://aspit.dfine.net/odensetrack
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

_login.php 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /*
  3. * Login page - Users are sent here if they are not properly logged in, or their login expired.
  4. */
  5. session_start();
  6. if(isset($_GET['logout'])) {
  7. $_SESSION = array();
  8. session_unset();
  9. session_destroy();
  10. header("Location: index.php?page=home");
  11. die("Error, please enable browser redirects.");
  12. }
  13. if (isset($_SESSION['user'])) {
  14. header("Location: index.php?page=home");
  15. die("Error, please enable browser redirects.");
  16. }
  17. mb_internal_encoding("utf-8"); // Internal encoding set to UTF-8, should fix some charset issues.
  18. require_once("include.php"); // Our includes.
  19. /*
  20. * Get variables and sanitize their inputs
  21. */
  22. $error = array();
  23. if (isset($_POST['u']) && isset($_POST['p'])) {
  24. // If mail and pw is set, lets do some sanitizng.
  25. if (filter_input(INPUT_POST, 'u', FILTER_DEFAULT) == true) {
  26. $email = $_POST['u'];
  27. } else {
  28. $error[] = "Email or username incorrect.";
  29. }
  30. if (filter_input(INPUT_POST, 'p', FILTER_DEFAULT) == true) {
  31. $password = $_POST['p'];
  32. } else {
  33. $error[] = "Email or username incorrect.";
  34. }
  35. $db = new DBClass();
  36. $query = "SELECT * FROM `" . Config::$db_tableusers . "` WHERE `username` = '" . $email . "'";
  37. if ($db->numRows($db->query($query)) >= 1) {
  38. $result = $db->fetchAll($db->query($query))[0];
  39. if (password_verify($password, $result['password']) && $email == $result['username']) {
  40. // SUCCESS!
  41. $_SESSION['user'] = $result['id'];
  42. $_SESSION['username'] = $result['username'];
  43. $_SESSION['lvl'] = $result['level'];
  44. header('Location: index.php?page=news');
  45. die("Error, please enable browser redirects.");
  46. } else {
  47. $error[] = "Mail wrong";
  48. }
  49. } else {
  50. $error[] = "Wrong email or password.";
  51. header('Location: index.php?page=login&error=1');
  52. }
  53. }
  54. /*
  55. * If no information was sent to the script, or the login was incorrect - HTML below here will be shown.
  56. */
  57. header('Location: ' . Config::$sys_url . '?page=login&error=1');
  58. die("Error, please enable browser redirects.");