cyberairman2013

Register.php

May 7th, 2013
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.52 KB | None | 0 0
  1. <?php
  2. include 'core/init.php';
  3. include 'includes/overall/header.php';
  4. if (empty($_POST) === false) {
  5.     $required_fields = array('username', 'password', 'password_again', 'first_name', 'last_name', 'email');
  6.     foreach ($_POST as $key=>$value) {
  7.         if (empty($value) && in_array($key, $required_fields) === true) {
  8.             $errors[] = 'Fields marked with an asterisk are required';
  9.             break 1;
  10.         }
  11.     }
  12.     if (empty($errors) === true) {
  13.         if (user_exists($_POST['username']) === true) {
  14.             $errors[] = 'Sorry, the username \'' . $_POST['username'] . '\' is already in use.';
  15.         }
  16.         if (preg_match("/\\s/", $_POST['username']) == true) {
  17.             $errors = 'Your username may not contain any spaces';
  18.         }
  19.         if (strlen($_POST['password']) < 8) {
  20.             $errors[] = 'Sorry, Your password is not strong enough. Passwords are required to be atleast eight(8) characters long.';
  21.         }
  22.         if ($_POST['password'] !== $_POST['password_again']) {
  23.             $errors[] = 'Your passwords do not match.';
  24.         }
  25.         if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) {
  26.             $errors[] = 'A valid email address is required for registration';
  27.         }
  28.         if (email_exists($_POST['email']) === true) {
  29.             $errors[] = 'Sorry, the email \'' . $_POST['email'] . '\' is already registered';
  30.         }
  31.     }
  32. }
  33. ?>      
  34. <h2>Pilot Registration</h2>
  35. <?php
  36. if (isset($_GET['success']) && empty($_GET['success'])) {
  37.     echo 'Registeration Successful!!!';
  38. } else {
  39.     if (empty($_POST) === false && empty($errors) === true) {
  40.         $register_data = array(
  41.             'username'      => $_POST['username'],
  42.             'password'      => $_POST['password'],
  43.             'first_name'    => $_POST['first_name'],
  44.             'last_name'     => $_POST['last_name'],
  45.             'email'         => $_POST['email']
  46.         );
  47.         register_user($register_data);
  48.         header('Location: index.php');
  49.         exit();
  50.        
  51.     } else if (empty($errors) === false) {
  52.         echo output_errors($errors);
  53.     }
  54.     ?>
  55.     <form action="" method="post">
  56.         <ul>
  57.             <li>
  58.                 Username*:<br>
  59.                 <input type="text" name="username" />
  60.             </li>
  61.             <li>
  62.                 Password*:<br>
  63.                 <input type="password" name="password" />
  64.             </li>
  65.             <li>
  66.                 Confirm Password*:<br>
  67.                 <input type="password" name="password_again" />
  68.             </li>
  69.             <li>
  70.                 First Name*:<br>
  71.                 <input type="text" name="first_name" />
  72.             </li>
  73.             <li>
  74.                 Last Name*:<br>
  75.                 <input type="text" name="last_name" />
  76.             </li>
  77.             <li>
  78.                 Email*:<br>
  79.                 <input type="text" name="email" />
  80.             </li>
  81.             <li>
  82.                 <input type="submit" value="Register" />
  83.             </li>
  84.         </ul>
  85.     </form>
  86.     <?php
  87.     }
  88.     include 'includes/overall/footer.php';?>
Advertisement
Add Comment
Please, Sign In to add comment