chpass.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. $pass = $_POST["password"];
  15. if($mysql->connect_error){
  16. die("Ошибка подключения". $mysql->connect_error);
  17. }
  18. // Получение данных пользователя из базы данных
  19. session_start();
  20. if (isset ($pass ))
  21. if (isset ($_COOKIE['id']))
  22. $user_id = $_COOKIE['id'];
  23. $userpass = $_SESSION['password'];
  24. $quary = "SELECT * FROM login WHERE password like'$userpass'";
  25. $result = mysqli_query($mysql, $quary);
  26. if(mysqli_num_rows($result) > 0 && $userpass == $pass)
  27. {
  28. header('Location: changepassword.php?message=Пароли+совпадают');
  29. echo "<script>window.location.href = 'changepassword.php';</script>";
  30. mysqli_close();
  31. session_abort();
  32. }
  33. if($userpass != $pass)
  34. {
  35. $query = "UPDATE login SET password = '$pass' WHERE id_user = $user_id";
  36. if($res = mysqli_query($mysql, $query))
  37. {
  38. session_start();
  39. $_SESSION['password'] = $pass;
  40. echo "<script>window.location.href = 'Account.php';</script>";
  41. }
  42. }
  43. }
  44. ?>