Advertisement
Guest User

Untitled

a guest
Sep 5th, 2017
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.49 KB | None | 0 0
  1. <?php
  2.  session_start();
  3.  
  4.  
  5.  if (isset($_POST['email'])) {
  6.    //Walidacja
  7.    $reg_form_correct=true;
  8.  
  9.    //Poprawnosc nick'a
  10.    $nick=$_POST['nick'];
  11.    //Dlugosc nickร„a
  12.    if ((strlen($nick)<3) || (strlen($nick)>20)) {
  13.      $reg_form_correct=false;
  14.      $_SESSION['e_nick']="Nickname needs 3 to 20 charters!";
  15.    }
  16.  
  17.   if (ctype_alnum($nick)==false) {
  18.     $reg_form_correct=false;
  19.     $_SESSION['e_nick']="Nickname can only be created with charters and numbers!";
  20.   }
  21.  
  22.     //Sprawdz poprawnosc adresu email
  23.     $email = $_POST['email'];
  24.     $emailB = filter_var($email, FILTER_SANITIZE_EMAIL);
  25.  
  26.     if ((filter_var($emailB, FILTER_VALIDATE_EMAIL)==false) || ($emailB != $email)) {
  27.       $reg_form_correct=false;
  28.       $_SESSION['e_email']="Valid e-mail!";
  29.     }
  30.  
  31.     //Sprawdz poprawnosc hasla
  32.     $password_1 = $_POST['password_1'];
  33.     $password_2 = $_POST['password_2'];
  34.     if ((strlen($password_1)<8) || (strlen($password_1)>20)) {
  35.       $reg_form_correct=false;
  36.       $_SESSION['e_pass']="Password needs 3 to 20 charters!";
  37.     }
  38.     //sprawdzanie identycznosci hasel
  39.     if ($password_1!=$password_2) {
  40.       $reg_form_correct=false;
  41.       $_SESSION['e_pass']="Passwords are not the same!";
  42.     }
  43.  
  44.     $haslo_hash = password_hash($password_1, PASSWORD_DEFAULT);
  45.  
  46.     // akceptacja reg.
  47.     if (!isset($_POST['regulamin'])) {
  48.       $reg_form_correct=false;
  49.       $_SESSION['e_terms']="You have to accept the terms!";
  50.     }
  51.  
  52.     // Czy to bot?
  53.     $sekret="6LfgYS8UAAAAAHK3BI52peprjIoP7U5qDvs_iIIN";
  54.  
  55.     $check_me = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$sekret.'&response='.$_POST['g-recaptcha-response']);
  56.  
  57.     $answer_captcha= json_decode($check_me);
  58.  
  59.     if($answer_captcha->success==false){
  60.       $reg_form_correct=false;
  61.       $_SESSION['e_bot']="Cant escape from captcha, bch";
  62.     }
  63.  
  64.     require_once"connect.php";
  65.  
  66.     mysqli_report(MYSQLI_REPORT_STRICT);
  67.  
  68.     try {
  69.         $sql_connection = new mysqli($host, $db_user, $db_password, $db_name);
  70.  
  71.           if ($sql_connection -> connect_errno!=0) {
  72.             throw new Exception(mysqli_connect_errno()); //Rzuc nowym wyjatek
  73.           }else {
  74.           //Czy @ juz istnieje?
  75.             $my_result = $sql_connection->query("SELECT id FROM uzytkownicy WHERE email='$email'");
  76.  
  77.           if (!$my_result) throw new Exception($sql_connection->error);
  78.  
  79.             $emails_validation = $my_result->num_rows;
  80.           if ($emails_validation>0) {
  81.             $reg_form_correct=false;
  82.             $_SESSION['e_email']="There is an acc with this email";
  83.           }
  84.  
  85.           //Czy login juz istnieje?
  86.           $my_result = $sql_connection->query("SELECT id FROM uzytkownicy WHERE user='$nick'");
  87.  
  88.           if (!$my_result) throw new Exception($sql_connection->error);
  89.  
  90.             $ile_takich_nickow = $my_result->num_rows;
  91.           if ($ile_takich_nickow>0) {
  92.             $reg_form_correct=false;
  93.             $_SESSION['e_nick']="There is a player with this nick already";
  94.           }
  95.  
  96.           if ($reg_form_correct==true) {
  97.             //Wszystkie testy zaliczone
  98.             if ($sql_connection->query("INSERT INTO uzytkownicy VALUES (NULL, '$nick', '$haslo_hash', '$email', '100', '100', '100', '14')")) {
  99.               $_SESSION['reg_fulfilled']=true;
  100.               header('Location: witamy.php');
  101.             }else {
  102.               throw new Exception($sql_connection->error);
  103.             }
  104.           }
  105.           $sql_connection->close();
  106.         }
  107.     } catch (Exception $e) {  //Zlap wyjatki, jesli jakies zostaly rzucone
  108.       echo '<span style="color:red;">Server error, see u later aligator</span>';
  109.       echo "<br> Info dev:".$e;
  110.     }
  111.  }
  112. ?>
  113.  
  114.  
  115. <!DOCTYPE html>
  116. <html>
  117.   <head>
  118.     <meta charset="utf-8">
  119.     <title>Settlerslike - Create ur free acc!</title>
  120.     <script src='https://www.google.com/recaptcha/api.js'></script>
  121.     <style>
  122.     .error{
  123.       color: red;
  124.       margin-top: 10px;
  125.       margin-bottom: 10px;
  126.     }
  127.     </style>
  128.   </head>
  129.   <body style="background-color: rgb(173, 173, 173);">
  130.  
  131.     <form  method="post">
  132.       Nickname: <br> <input type="text" name="nick"> <br>
  133.       <?php
  134.       if (isset($_SESSION['e_nick'])) {
  135.         echo '<div class="error">'.$_SESSION['e_nick'].'</div>';
  136.         unset($_SESSION['e_nick']);
  137.       }
  138.       ?>
  139.  
  140.       E-mail: <br> <input type="text" name="email"> <br>
  141.       <?php
  142.       if (isset($_SESSION['e_email'])) {
  143.         echo '<div class="error">'.$_SESSION['e_email'].'</div>';
  144.         unset($_SESSION['e_email']);
  145.       }
  146.       ?>
  147.  
  148.       Password: <br> <input type="password" name="password_1"> <br>
  149.       <?php
  150.       if (isset($_SESSION['e_pass'])) {
  151.         echo '<div class="error">'.$_SESSION['e_pass'].'</div>';
  152.         unset($_SESSION['e_pass']);
  153.       }
  154.       ?>
  155.       Re-Password: <br> <input type="password" name="password_2"> <br>
  156.       <label><input type="checkbox" name="regulamin" value=""> Me accept the term, yes</label><br>
  157.       <?php
  158.       if (isset($_SESSION['e_terms'])) {
  159.         echo '<div class="error">'.$_SESSION['e_terms'].'</div>';
  160.         unset($_SESSION['e_terms']);
  161.       }
  162.       ?>
  163.       <div class="g-recaptcha" data-sitekey="6LfgYS8UAAAAANB8sauiB9FMdWWK5YARwN2dL5cB"></div> <br>
  164.       <?php
  165.       if (isset($_SESSION['e_bot'])) {
  166.         echo '<div class="error">'.$_SESSION['e_bot'].'</div>';
  167.         unset($_SESSION['e_bot']);
  168.       }
  169.       ?>
  170.       <button type="submit" name="button">Reggister</button>
  171.     </form>
  172.  
  173.   </body>
  174. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement