chlogin.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. if(!isset($_COOKIE['id']))
  3. {
  4. echo "<script>window.location.href = 'index.php';</script>";
  5. }
  6. else
  7. {
  8. session_start();
  9. $host = "blueris.beget.tech";
  10. $username = "blueris_base";
  11. $password = "Qwer123.";
  12. $database = "blueris_base";
  13. $mysql = new mysqli($host, $username, $password, $database);
  14. $login = $_POST["login"];
  15. if($mysql->connect_error){
  16. die("Ошибка подключения". $mysql->connect_error);
  17. }
  18. // Получение данных пользователя из базы данных
  19. session_start();
  20. if (isset ($login))
  21. if (isset ($_COOKIE['id']))
  22. $user_id = $_COOKIE['id'];
  23. $userlogin = $_SESSION['login'];
  24. $quary = "SELECT * FROM login WHERE login like'$login'";
  25. $result = mysqli_query($mysql, $quary);
  26. if(mysqli_num_rows($result) > 0 && $userlogin == $login)
  27. {
  28. header('Location: changelogin.php?message=Логины+совпадают');
  29. echo "<script>window.location.href = 'changelogin.php';</script>";
  30. mysqli_close();
  31. session_abort();
  32. }
  33. if(mysqli_num_rows($result) > 0 && $userlogin != $login)
  34. {
  35. header('Location: changelogin.php?message=Логин+существует');
  36. echo "<script>window.location.href = 'changelogin.php';</script>";
  37. mysqli_close();
  38. session_abort();
  39. }
  40. session_abort();
  41. if($userlogin != $login && mysqli_num_rows($result) == 0)
  42. {
  43. $query = "UPDATE login SET login = '$login' WHERE id_user = $user_id";
  44. if($res = mysqli_query($mysql, $query))
  45. {
  46. session_start();
  47. $_SESSION['login'] = $login;
  48. echo "<script>window.location.href = 'Account.php';</script>";
  49. }
  50. }
  51. }
  52. ?>