login.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. $host = "provalgk.beget.tech";
  3. $username = "provalgk_user";
  4. $password = "Qwer123.";
  5. $database = "provalgk_user";
  6. // Получение введенного логина и пароля из формы
  7. $user = $_POST['login'];
  8. $pass = $_POST['password'];
  9. // Подключение к базе данных
  10. $mysql = new mysqli($host, $username, $password, $database);
  11. // Проверка соединения
  12. if($mysql->connect_error){
  13. die("Ошибка подключения". $mysql->connect_error);
  14. }
  15. // Подготовка запроса для проверки логина
  16. $quary = "SELECT * FROM Login WHERE login like'$user' AND password like '$pass'";
  17. $result = mysqli_query($mysql, $quary);
  18. $row = mysqli_fetch_assoc($result);
  19. $id = $row['id_user'];
  20. $userpass = $row['password'];
  21. $userlogin = $row['login'];
  22. $role = $row['role'];
  23. if (mysqli_num_rows($result) > 0) {
  24. if($role == 1)
  25. {
  26. session_start();
  27. $_SESSION['id'] = $id;
  28. $_SESSION['password'] = $userpass;
  29. $_SESSION['login'] = $userlogin;
  30. $_SESSION['role'] = $role;
  31. echo "<script>localStorage.setItem('login', '$user');
  32. window.location.href = 'indexforadmin.html';</script>";
  33. }
  34. else
  35. {
  36. session_start();
  37. $_SESSION['id'] = $id;
  38. $_SESSION['password'] = $userpass;
  39. $_SESSION['login'] = $userlogin;
  40. $_SESSION['role'] = $role;
  41. echo "<script>localStorage.setItem('login', '$user');
  42. window.location.href = 'indexforuser.html';</script>";
  43. }
  44. }
  45. else {
  46. header('Location: Login.html?message=Неверные+данные');
  47. echo "<script>window.location.href = 'Login.html';</script>";
  48. }
  49. // Закрытие соединения с базой данных
  50. ?>