Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- if (isset($_POST['email'])) {
- //Walidacja
- $reg_form_correct=true;
- //Poprawnosc nick'a
- $nick=$_POST['nick'];
- //Dlugosc nickรa
- if ((strlen($nick)<3) || (strlen($nick)>20)) {
- $reg_form_correct=false;
- $_SESSION['e_nick']="Nickname needs 3 to 20 charters!";
- }
- if (ctype_alnum($nick)==false) {
- $reg_form_correct=false;
- $_SESSION['e_nick']="Nickname can only be created with charters and numbers!";
- }
- //Sprawdz poprawnosc adresu email
- $email = $_POST['email'];
- $emailB = filter_var($email, FILTER_SANITIZE_EMAIL);
- if ((filter_var($emailB, FILTER_VALIDATE_EMAIL)==false) || ($emailB != $email)) {
- $reg_form_correct=false;
- $_SESSION['e_email']="Valid e-mail!";
- }
- //Sprawdz poprawnosc hasla
- $password_1 = $_POST['password_1'];
- $password_2 = $_POST['password_2'];
- if ((strlen($password_1)<8) || (strlen($password_1)>20)) {
- $reg_form_correct=false;
- $_SESSION['e_pass']="Password needs 3 to 20 charters!";
- }
- //sprawdzanie identycznosci hasel
- if ($password_1!=$password_2) {
- $reg_form_correct=false;
- $_SESSION['e_pass']="Passwords are not the same!";
- }
- $haslo_hash = password_hash($password_1, PASSWORD_DEFAULT);
- // akceptacja reg.
- if (!isset($_POST['regulamin'])) {
- $reg_form_correct=false;
- $_SESSION['e_terms']="You have to accept the terms!";
- }
- // Czy to bot?
- $sekret="6LfgYS8UAAAAAHK3BI52peprjIoP7U5qDvs_iIIN";
- $check_me = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$sekret.'&response='.$_POST['g-recaptcha-response']);
- $answer_captcha= json_decode($check_me);
- if($answer_captcha->success==false){
- $reg_form_correct=false;
- $_SESSION['e_bot']="Cant escape from captcha, bch";
- }
- require_once"connect.php";
- mysqli_report(MYSQLI_REPORT_STRICT);
- try {
- $sql_connection = new mysqli($host, $db_user, $db_password, $db_name);
- if ($sql_connection -> connect_errno!=0) {
- throw new Exception(mysqli_connect_errno()); //Rzuc nowym wyjatek
- }else {
- //Czy @ juz istnieje?
- $my_result = $sql_connection->query("SELECT id FROM uzytkownicy WHERE email='$email'");
- if (!$my_result) throw new Exception($sql_connection->error);
- $emails_validation = $my_result->num_rows;
- if ($emails_validation>0) {
- $reg_form_correct=false;
- $_SESSION['e_email']="There is an acc with this email";
- }
- //Czy login juz istnieje?
- $my_result = $sql_connection->query("SELECT id FROM uzytkownicy WHERE user='$nick'");
- if (!$my_result) throw new Exception($sql_connection->error);
- $ile_takich_nickow = $my_result->num_rows;
- if ($ile_takich_nickow>0) {
- $reg_form_correct=false;
- $_SESSION['e_nick']="There is a player with this nick already";
- }
- if ($reg_form_correct==true) {
- //Wszystkie testy zaliczone
- if ($sql_connection->query("INSERT INTO uzytkownicy VALUES (NULL, '$nick', '$haslo_hash', '$email', '100', '100', '100', '14')")) {
- $_SESSION['reg_fulfilled']=true;
- header('Location: witamy.php');
- }else {
- throw new Exception($sql_connection->error);
- }
- }
- $sql_connection->close();
- }
- } catch (Exception $e) { //Zlap wyjatki, jesli jakies zostaly rzucone
- echo '<span style="color:red;">Server error, see u later aligator</span>';
- echo "<br> Info dev:".$e;
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>Settlerslike - Create ur free acc!</title>
- <script src='https://www.google.com/recaptcha/api.js'></script>
- <style>
- .error{
- color: red;
- margin-top: 10px;
- margin-bottom: 10px;
- }
- </style>
- </head>
- <body style="background-color: rgb(173, 173, 173);">
- <form method="post">
- Nickname: <br> <input type="text" name="nick"> <br>
- <?php
- if (isset($_SESSION['e_nick'])) {
- echo '<div class="error">'.$_SESSION['e_nick'].'</div>';
- unset($_SESSION['e_nick']);
- }
- ?>
- E-mail: <br> <input type="text" name="email"> <br>
- <?php
- if (isset($_SESSION['e_email'])) {
- echo '<div class="error">'.$_SESSION['e_email'].'</div>';
- unset($_SESSION['e_email']);
- }
- ?>
- Password: <br> <input type="password" name="password_1"> <br>
- <?php
- if (isset($_SESSION['e_pass'])) {
- echo '<div class="error">'.$_SESSION['e_pass'].'</div>';
- unset($_SESSION['e_pass']);
- }
- ?>
- Re-Password: <br> <input type="password" name="password_2"> <br>
- <label><input type="checkbox" name="regulamin" value=""> Me accept the term, yes</label><br>
- <?php
- if (isset($_SESSION['e_terms'])) {
- echo '<div class="error">'.$_SESSION['e_terms'].'</div>';
- unset($_SESSION['e_terms']);
- }
- ?>
- <div class="g-recaptcha" data-sitekey="6LfgYS8UAAAAANB8sauiB9FMdWWK5YARwN2dL5cB"></div> <br>
- <?php
- if (isset($_SESSION['e_bot'])) {
- echo '<div class="error">'.$_SESSION['e_bot'].'</div>';
- unset($_SESSION['e_bot']);
- }
- ?>
- <button type="submit" name="button">Reggister</button>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement