Advertisement
Guest User

Register form

a guest
Jun 1st, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.94 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. // if user is logged in redirect him to index page
  5. if ($general->is_logged() === true) {
  6.     header('Location: index.php');
  7.     exit();
  8. }
  9.  
  10. // get list of countries
  11. $country = $teams->get_country();
  12.  
  13. require_once 'core/classes/recaptchalib.php';
  14. $publickey = "****************************************";
  15. $privatekey = "*****************************************";
  16.  
  17. // process form
  18. if (isset($_POST['register']))
  19. {
  20.     if (isset($_POST['username']) &&
  21.         isset($_POST['nickname']) &&
  22.         isset($_POST['password']) &&
  23.         isset($_POST['repeat_password']) &&
  24.         isset($_POST['email']) &&
  25.         isset($_POST['repeat_email']) &&
  26.         isset($_POST['gender']) &&
  27.         isset($_POST['country']) &&
  28.         isset($_POST['recaptcha_challenge_field']) &&
  29.         isset($_POST['recaptcha_challenge_field']))
  30.     {
  31.         $username   = trim($general->safe_input($_POST['username']));
  32.         $nickname   = trim($general->safe_input($_POST['nickname']));
  33.         $password   = trim($general->safe_input($_POST['password']));
  34.         $rpassword  = trim($general->safe_input($_POST['repeat_password']));
  35.         $email      = trim($general->safe_input($_POST['email']));
  36.         $remail     = trim($general->safe_input($_POST['repeat_email']));
  37.         $gender     = trim($general->safe_input($_POST['gender']));
  38.         $cntry      = $general->safe_input($_POST['country']);
  39.         $date_registered = time();
  40.         $password_hash = $general->safepass($password);
  41.         // captcha
  42.         $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
  43.  
  44.         // if username is empty
  45.         if (empty($username)) {
  46.             $error[] = 'Username is empty.';
  47.  
  48.         // if username already exists
  49.         } elseif ($users->user_exists($username) === true) {
  50.             $error[] = 'Username in use, please choose another.';
  51.        
  52.         // username must be between 3 and 20 characters long
  53.         } elseif (strlen($username) < 3 || strlen($username) > 20) {
  54.             $error[] = 'Username must be between 3 and 20 charaters long.';
  55.         }
  56.        
  57.         // if nickname is empty
  58.         if (empty($nickname)) {
  59.             $error[] = 'Nickname is empty.';
  60.  
  61.         // if nickname in use
  62.         } elseif ($users->nick_exists($nickname) === true) {
  63.             $error[] = 'Nickname in use, please choose another.';
  64.  
  65.         // nickname must be between 3 and 20 characters long
  66.         } elseif (strlen($nickname) < 3 || strlen($nickname) > 20) {
  67.             $error[] = 'Nickname must be between 3 and 20 characters long.';
  68.         }
  69.                
  70.         // if passowrd field is empty
  71.         if (empty($password)) {
  72.             $error[] = 'Password filed is empty.';
  73.         }
  74.  
  75.         // if password repeat field is empty
  76.         if (empty($rpassword)) {
  77.             $error[] = 'Repeat password filed is empty';
  78.         }
  79.  
  80.         // if password and repeat password is not empty
  81.         if (!empty($password) && !empty($rpassword)) {
  82.  
  83.             // passwords match ? if not throw error message
  84.             if ($password != $rpassword) {
  85.                 $error[] = 'Passwords don\'t match.';
  86.  
  87.             // password must be between 6 and 30 characters long
  88.             } elseif (strlen($password) < 6 || strlen($password) > 30) {
  89.                 $error[] = 'Password must be between 6 and 30 characters long.';
  90.             }
  91.         }
  92.        
  93.         // is email empty
  94.         if (empty($email)) {
  95.             $error[] = 'Email filed is empty.';
  96.         }
  97.  
  98.         // is repeat email is empty
  99.         if (empty($remail)) {
  100.             $error[] = 'Repeat email filed is empty.';
  101.         }
  102.        
  103.         // if email and repeat email is not empty
  104.         if (!empty($email) && !empty($remail)) {
  105.  
  106.             // if emails are not same
  107.             if ($email != $remail) {
  108.                 $error[] = 'Emails don\'t match.';
  109.  
  110.             // if email and repeat email is same
  111.             } elseif ($email == $remail) {
  112.  
  113.                 // is email valid
  114.                 if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  115.                     $error[] = 'Invalid email format.';
  116.  
  117.                 // is email in use
  118.                 } elseif ($users->email_exists($email) === true) {
  119.                     $error[] = 'Email in use, please choose another.';
  120.                
  121.                 // email must be between 10 and 30 characters long
  122.                 } elseif (strlen($email) < 10 || strlen($email) > 30) {
  123.                     $error[] = 'Email must be between 10 and 30 characters long.';
  124.                 }
  125.             }
  126.         }
  127.  
  128.         // if gender is empty
  129.         if (empty($gender)) {
  130.             $error[] = 'Please select gender.';
  131.         }
  132.  
  133.         // if country is empty
  134.         if (empty($cntry)) {
  135.             $error[] = 'Please select country.';
  136.         }
  137.  
  138.         // check if capthha is valid
  139.         if (!$resp->is_valid) {
  140.             $error[] = 'Invalid captcha code.';
  141.         }
  142.  
  143.         // if no errors register user
  144.         if (empty($error) === true) {
  145.             unset($_POST); // clean $_post variable
  146.             echo 'REGISTER USER !';
  147.         }
  148.  
  149.  
  150.    
  151.         $add_user = $users->register_user($username, $password_hash, $email, $gender, $date_registered, $cntry, $nickname);
  152.  
  153.         /*          if ($DBH->lastInsertId())
  154.                     {
  155.                         header('Location: index.php?page=register_success');
  156.                         exit();
  157.                     }
  158.                     else
  159.                     {
  160.                         $error = '<p class="error-msg">There was a problem, please try again.</p>';
  161.                     }*/
  162.        
  163.     }
  164. }
  165.  
  166. ?>
  167.  
  168.  <script type="text/javascript">
  169.  var RecaptchaOptions = {
  170.     theme : 'clean'
  171.  };
  172.  </script>
  173.  
  174. <h3>Register</h3>
  175.  
  176. <?php
  177. if (!empty($error)) {
  178.     echo '<div style="padding:10px;margin:0 10px;border:1px solid #f3f3f3;background:#E35454;color:#fff;"><ul style="margin:0 0 0 20px;">';
  179.     foreach ($error as $error) {
  180.         echo '<li>'.$error. '</li>';
  181.     }
  182.     echo '</ul></div>';
  183. }
  184. ?>
  185.  
  186. <form action="" method="POST" class="register-form">
  187.     <input type="text" name="username" size="40" maxlength="20" placeholder="Username" value="<?php if (isset($_POST['username'])) { echo htmlentities($_POST['username'], ENT_QUOTES, "UTF-8"); } ?>" required>&nbsp;&nbsp;&nbsp;
  188.     <input type="text" name="nickname" size="40" maxlength="20" placeholder="Nickname" value="<?php if (isset($_POST['nickname'])) { echo htmlentities($_POST['nickname'], ENT_QUOTES, "UTF-8"); } ?>" required><br /><br />
  189.     <input type="password" name="password" size="40" maxlength="30" placeholder="Password" required>&nbsp;&nbsp;&nbsp;
  190.     <input type="password" name="repeat_password" size="40" maxlength="30" placeholder="Repeat password" required><br /><br />
  191.     <input type="text" name="email" size="40" maxlength="30" placeholder="Email" value="<?php if (isset($_POST['email'])) { echo htmlentities($_POST['email'], ENT_QUOTES, "UTF-8"); } ?>" required>&nbsp;&nbsp;&nbsp;
  192.     <input type="text" name="repeat_email" size="40" maxlength="30" placeholder="Repeat email" value="<?php if (isset($_POST['repeat_email'])) { echo htmlentities($_POST['repeat_email'], ENT_QUOTES, "UTF-8"); } ?>" required><br /><br />
  193.     <select name="gender" required>
  194.         <option value="">Select gender</option>
  195.         <option value="Male">Male</option>
  196.         <option value="Female">Female</option>
  197.     </select>&nbsp;&nbsp;&nbsp;
  198.     <select name="country" style="width: 215px;" required>
  199.         <option value="">Select county</option>
  200.             <?php
  201.                 foreach ($country as $key)
  202.                 {
  203.                     echo '<option value="'.$key['name'].','.$key['alpha_2'].'">'.$key['name'].'</option>';
  204.                 }
  205.             ?>
  206.     </select>
  207.     <br><br>
  208.     <center><?php echo recaptcha_get_html($publickey); ?></center>
  209.     <br>
  210.     <center><input type="submit" name="register" value="Register" class="small-button"></center>
  211. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement