em89

RegistrationForm

Jul 14th, 2014
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.82 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Register</title>
  5.     <link rel="stylesheet" type="text/css" href="style.css">
  6. </head>
  7. <body>
  8.     <div class="regForm">
  9.         <form method="POST">
  10.             <label class="left" for="regName">User Name:</label>
  11.             <input type="text" name="regName" id="regName">
  12.             <br>
  13.             <label class="left" for="passF">Password:</label>
  14.             <input type="password" name="regPass1" id="passF">
  15.             <br>
  16.             <label class="left" for="passR">Repeat Password:</label>
  17.             <input type="password" name="regPass2" id="passR">
  18.             <br>
  19.             <label class="left" for="question">Secret Queston:</label>
  20.             <input type="text" name="question" id="question">
  21.             <br>
  22.             <label class="left" for="answer">Secret Answer:</label>
  23.             <input type="text" name="answer" id="amswer">
  24.             <br>
  25.             <label class="left" for="email">Email:</label>
  26.             <input type="email" name="email" id="email">
  27.             <br>
  28.             <label class="left" for="fName">First Name:</label>
  29.             <input type="text" name="fName" id="fName">
  30.             <br>
  31.             <label class="left" for="lName">Last Name:</label>
  32.             <input type="text" name="lName" id="lName">
  33.             <br>
  34.             <label class="left">Sex:</label>
  35.             <input type="radio" name="sex" value="male">male
  36.             <input type="radio" name="sex" value="female">female
  37.             <br>
  38.             <label class="left" for="birth">Birthday:</label>
  39.             <input type="text" name="day" id="birth">
  40.             <input type="text" name="month" id="birth">
  41.             <input type="text" name="year" id="birth">
  42.             <br>
  43.             <input type="submit" value="Create Profile" />
  44.         </form>
  45.     </div>
  46.     <?php
  47.         $userName = trim($_POST['regName']);
  48.         $userName = str_replace('!', '', $userName);
  49.         $userPass1 = trim($_POST['regPass1']);
  50.         $userPass1 = str_replace('!', '', $userPass1);
  51.         $userPass2 = trim($_POST['regPass2']);
  52.         $userPass2 = str_replace('!', '', $userPass2);
  53.         $userQuest = trim($_POST['question']);
  54.         //$userQuest = str_repeat("1", " ", $userQuest);
  55.         $userAns = trim($_POST['answer']);
  56.         //$userAns = str_repeat("1", " ", $userAns);
  57.         $userEmail = $_POST['email'];
  58.         $userFirst = $_POST['fName'];
  59.         $userLast = $_POST['lName'];
  60.         $sex = $_POST['sex'];
  61.         $birth = $_POST['day']."!".$_POST['month']."!".$_POST['year'];
  62.         $error = false;
  63.         if ($_POST) {
  64.             if (empty($_POST['regName']) || empty($_POST['regPass1']) || empty($_POST['regPass2']) || empty($_POST['question']) || empty($_POST['answer']) || empty($_POST['email']) || empty($_POST['fName']) || empty($_POST['lName']) || empty($_POST['sex']) || empty($_POST['day']) || empty($_POST['month']) || empty($_POST['year'])) {
  65.                 echo "<p>You have to fill all fields!</p>";
  66.                 $error=true;
  67.             }
  68.             else {
  69.                 if (!(preg_match('/^\w{3,}$/', $userName))) {
  70.                     echo '<p>Invalid User Name!</p>';
  71.                     $error=true;
  72.                 }
  73.                
  74.                 if (!(preg_match('/^\w{6,}$/', $userPass1))) {
  75.                     echo '<p>Invalid Password!</p>';
  76.                     $error=true;
  77.                 }
  78.                
  79.                 if ($userPass1 != $userPass2) {
  80.                     echo "<p>Password doesn't match!</p>";
  81.                     $error=true;
  82.                 }
  83.                
  84.                 if (!(preg_match('/^\w{3,}$/', $userQuest))) {
  85.                     echo "<p>Use only letters and numbers!</p>";
  86.                     $error=true;
  87.                 }
  88.  
  89.                 if (!(preg_match('/^\w{3,}$/', $userAns))) {
  90.                     echo "<p>Use only letters and numbers!</p>";
  91.                     $error=true;
  92.                 }
  93.  
  94.                 $reg = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/";
  95.                 if (!(preg_match($reg, $userEmail))) {
  96.                     echo '<p>Invalid email!</p>';
  97.                     $error=true;
  98.                 }
  99.                 if (!(preg_match('/^\w{3,}$/', $userFirst))) {
  100.                     echo '<p>Invalid First Name!</p>';
  101.                     $error=true;
  102.                 }
  103.                
  104.                 if (!(preg_match('/^\w{3,}$/', $userLast))) {
  105.                     echo '<p>Invalid Last Name!</p>';
  106.                     $error=true;
  107.                 }
  108.                 if (!(preg_match('/[0-9]{2}$/', $_POST['day']))) {
  109.                     echo '<p>Invalid date!</p>';
  110.                     $error=true;
  111.                 }
  112.                 if (!(preg_match('/[[a-zA-Z]$/', $_POST['month']))) {
  113.                     echo '<p>Invalid month!</p>';
  114.                     $error=true;
  115.                 }
  116.                 if (!(preg_match('/[0-9]{4}$/', $_POST['year']))) {
  117.                     echo '<p>Invalid year!</p>';
  118.                     $error=true;
  119.                 }
  120.             }
  121.             $string = file_get_contents('data.txt');
  122.             $string = explode("\n", $string);
  123.             foreach ($string as $key => $value) {
  124.                 $value = explode("!", $value);
  125.                 if ($userName == $value[0]) {
  126.                     echo "<p>Username already exists.</p>";
  127.                     $error = true;
  128.                     break;
  129.                 }
  130.             }
  131.    
  132.             if (!$error) {
  133.                 $result = $userName."!".$userPass1."!".$userQuest."!".$userAns."!".$userEmail."!".$userFirst."!".$userLast."!".$sex."!".$birth."\n";
  134.                 file_put_contents('data.txt', $result,FILE_APPEND);
  135.                
  136.             }
  137.            
  138.         }
  139.     ?>
  140. </body>
  141. </html>
Advertisement
Add Comment
Please, Sign In to add comment