Registration.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. $host = "provalgk.beget.tech";
  3. $username = "provalgk_user";
  4. $password = "Qwer123.";
  5. $database = "provalgk_user";
  6. $email = $_POST["email"];
  7. $login = $_POST["login"];
  8. $pass = $_POST["password"];
  9. $mysql = new mysqli($host, $username, $password, $database);
  10. // Проверка соединения
  11. if($mysql->connect_error){
  12. die("Ошибка подключения". $mysql->connect_error);
  13. }
  14. $quary = "SELECT * FROM Login WHERE login like'$login'";
  15. $result = mysqli_query($mysql, $quary);
  16. if(mysqli_num_rows($result) > 0)
  17. {
  18. header('Location: Registration.html?message=Логин+существует');
  19. echo "<script>window.location.href = 'Registration.html';</script>";
  20. mysqli_close();
  21. }
  22. $quary = "SELECT * FROM Login WHERE email like '$email'";
  23. $result1 = mysqli_query($mysql, $quary);
  24. if(mysqli_num_rows($result1) > 0)
  25. {
  26. header('Location: Registration.html?message=Почта+существует');
  27. echo "<script>window.location.href = 'Registration.html';</script>";
  28. mysqli_close();
  29. }
  30. if(mysqli_num_rows($result) == 0 && mysqli_num_rows($result1) == 0)
  31. {
  32. $permitted_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  33. $kod = substr(str_shuffle($permitted_chars), 0, 10);
  34. $message = "Проверочный код: ".$kod;
  35. $to = $email;
  36. $from = "provalenkoludmila@gmail.com";
  37. $subject = "Проверочный код для ".$login;
  38. $subject = "=?utf-8?B?".base64_encode($subject)."?=";
  39. $headers = "From: $from\r\nReply-to: $from\r\nContent-type: text/html; charset=utf-8\r\n";
  40. mail($to, $subject, $message, $headers);
  41. session_start();
  42. $_SESSION['login'] = $login;
  43. $_SESSION['password'] = $pass;
  44. $_SESSION['email'] = $email;
  45. $_SESSION['kod'] = $kod;
  46. echo "<script>window.location.href = 'EmailCheck.html';</script>";
  47. }
  48. ?>