Advertisement
Guest User

Untitled

a guest
Jan 13th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.74 KB | None | 0 0
  1. <?php
  2. error_reporting(0);
  3. require_once('func/db_connect.php');
  4. require_once('func/func.php');
  5. $submit = $_POST['check'];
  6. $username = $_POST['username'];
  7. $password = $_POST['password'];
  8. $repassword = $_POST['repassword'];
  9. $email = $_POST['email'];
  10. $secreatq = $_POST['secretq'];
  11. $secreta = $_POST['secreta'];
  12. $result = mysqli_query($conn, "SELECT username FROM user_info WHERE username='".$username."'");
  13.  
  14. function dieWith($message) {
  15.     header('refresh: 3; url=index.php');
  16.     exit($message);
  17. }
  18.  
  19. if ($submit == 1) {
  20.  
  21.     if (mysqli_num_rows($result) != 0)
  22.     {
  23.         dieWith("Username already exists.");
  24.     }
  25.     if(strlen($username) == 0){
  26.         dieWith("You can't leave the username field blank.");
  27.     }
  28.     if(strlen($username) < 3){
  29.         dieWith("Your username is too short.");
  30.     }
  31.     if(strlen($username) > 15){
  32.         dieWith("Your username is too long.");
  33.     }
  34.     if(strlen($password) == 0){
  35.         dieWith("You can't leave the password field blank.");
  36.     }
  37.     if(strlen($password) < 3){
  38.         dieWith("Your password is too short.");
  39.     }
  40.     if(strlen($password) > 50){
  41.         dieWith("Your password is too long.");
  42.     }
  43.     if($repassword != $password){
  44.         dieWith("Your passwords doesn't match.");
  45.     }
  46.     if(strlen($email) == 0){
  47.         dieWith("You can't leave the e-mail field blank.");
  48.     }
  49.     if(strlen($email) < 3){
  50.         dieWith("Your e-mail is invalid.");
  51.     }
  52.     if(strlen($email) > 100){
  53.         dieWith("Your e-mail is invalid.");
  54.     }
  55.     if(strlen($secreatq) == 0){
  56.         dieWith("Please enter your secret question.");
  57.     }
  58.     if(strlen($secreatq) < 3){
  59.         dieWith("Your secret question is too short.");
  60.     }
  61.     if(strlen($secreatq) > 50){
  62.         dieWith("Your secret question is to long.");
  63.     }
  64.     if(strlen($secreta) == 0){
  65.         dieWith("Please enter your secret answer.");
  66.     }
  67.     if(strlen($secreta) < 3){
  68.         dieWith("Your secret answer is too short.");
  69.     }
  70.     if(strlen($secreta) > 50){
  71.         dieWith("Your secret answer is to long.");
  72.     }
  73.  
  74. // Register user
  75.     $sql = "INSERT INTO user_info (username, password, email, secret_question, secret_answer) VALUES ('$username', '$password', '$email','$secreatq','$secreta')";
  76.     mysqli_query($conn, $sql);
  77.     echo 'Congratulations, your username <strong>'.$username.'</strong> is successfully registered. You can now log in. <br />';
  78.     echo 'Username: '.$username. '<br />';
  79.     echo 'Password: '.$password. '<br />';
  80.     echo 'E-Mail: '.$email. '<br />';
  81.     echo 'Secret Question: '.$secreatq. '<br />';
  82.     echo 'Secret Answer: '.$secreta. '<br />';
  83.     dieWith("You will be redirected to the index page after 5 seconds.");
  84.     header('refresh: 5; url=index.php');
  85. }
  86. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement