rmfleck80

register reg.php

Apr 7th, 2016
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.81 KB | None | 0 0
  1. <?php
  2.  
  3. if(!isset($_POST['Capnumber']) || !isset($_POST['Captcha']) ) {
  4.     echo "<!DOCTYPE html>";
  5.     echo "<html>";
  6.     echo "<head>";
  7.     echo "<link rel='stylesheet' type='text/css' href='../css/style.css'>";
  8.     echo "<link rel='icon' type='image/ico' href='../images/favicon.ico'>";
  9.     echo "</head>";
  10.     echo "<body>";
  11.     echo "<div id='maindiv'>";
  12.         echo "<div id='formdiv'>";
  13.             echo "<p>CAPTCHA mismatch</p>";
  14.             echo "<p>Please go <a href='../register'>back</a> to fix these errors.</p>";
  15.         echo "</div>";
  16.     echo "</div>";     
  17.     echo "</body>";
  18.     echo "</html>";
  19.    
  20.     die();
  21. } else {
  22.  
  23. switch ($_POST['Capnumber']) {
  24.     case "cap1":
  25.         $captchanum = "6";
  26.             break;
  27.         case "cap2":
  28.         $captchanum = "5";
  29.             break;
  30.         case "cap3":
  31.         $captchanum = "7";
  32.             break;
  33.         case "cap4":
  34.         $captchanum = "4";
  35.             break;
  36.         case "cap5":
  37.         $captchanum = "8";
  38.             break;
  39.         case "cap6":
  40.         $captchanum = "9";
  41.             break;
  42. }
  43.  
  44.     if($captchanum <> $_POST['Captcha']) {
  45.         //CAPTCHA FAILED
  46.         echo "<!DOCTYPE html>";
  47.         echo "<html>";
  48.         echo "<head>";
  49.         echo "<link rel='stylesheet' type='text/css' href='../css/style.css'>";
  50.         echo "<link rel='icon' type='image/ico' href='../images/favicon.ico'>";
  51.         echo "</head>";
  52.         echo "<body>";
  53.         echo "<div id='maindiv'>";
  54.             echo "<div id='formdiv'>";
  55.                 echo "<p>CAPTCHA mismatch</p>";
  56.                 echo "<p>Please go <a href='../register'>back</a> to fix these errors.</p>";
  57.             echo "</div>";
  58.         echo "</div>";     
  59.         echo "</body>";
  60.         echo "</html>";
  61.        
  62.         die();
  63.     }
  64. }
  65.  
  66.  
  67.  
  68.  
  69. if(isset($_POST['Email'])){
  70.  
  71.  
  72. //error code
  73.  
  74. function died($error){
  75.  
  76. echo "<!DOCTYPE html>";
  77. echo "<html>";
  78. echo "<head>";
  79.     echo "<link rel='stylesheet' type='text/css' href='../css/style.css'>";
  80.     echo "<link rel='icon' type='image/ico' href='../images/favicon.ico'>";
  81. echo "</head>";
  82. echo "<body>";
  83.     echo "<div id='maindiv'>";
  84.         echo "<div id='formdiv'>";
  85.             echo "<p>We are sorry, but there were error(s) found with the form you submitted.</p>";
  86.             echo "<p>These errors appear below.</p><br/><br/>";
  87.             echo "<p>" . $error . "</p><br/><br/>";
  88.             echo "<p>Please go <a href='../register'>back</a> to fix these errors.</p><br/>";
  89.         echo "</div>";
  90.     echo "</div>";     
  91. echo "</body>";
  92. echo "</html>";
  93.            
  94. die();
  95. }
  96.  
  97. function nooptin($error){
  98. echo "<!DOCTYPE html>";
  99. echo "<html>";
  100. echo "<head>";
  101.     echo "<link rel='stylesheet' type='text/css' href='../css/style.css'>";
  102.     echo "<link rel='icon' type='image/ico' href='../images/favicon.ico'>";
  103. echo "</head>";
  104. echo "<body>";
  105.     echo "<div id='maindiv'>";
  106.         echo "<div id='formdiv'>";
  107.             echo "<p>You must opt in to receive communication from TEST Pharmaceuticals.<br/><a href='../register'>Back</a></p>";
  108.         echo "</div>";
  109.     echo "</div>";     
  110. echo "</body>";
  111. echo "</html>";
  112.  
  113. die();
  114. }
  115.  
  116. // validation
  117.  
  118. if(!isset($_POST['Optin'])) {
  119.     nooptin('You must opt in to receive communication from TEST Pharmaceuticals.');
  120. }
  121.  
  122. if(!isset($_POST['Name']) ||
  123. !isset($_POST['Email'])) {
  124.     died('We are sorry but there appears to be a problem with the form you submitted.');
  125. }
  126.  
  127. $name = $_POST['Name'];
  128. $email = $_POST['Email'];
  129. $optin = $_POST['Optin'];
  130.  
  131.  
  132. $error_message = "";
  133. $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  134. if(!preg_match($email_exp, $email)){
  135. $error_message .='The email address you entered does not appear to be valid.<br/>';
  136. }
  137. $string_exp = "/^[[A-Za-z' - ]+$/";
  138. if (!preg_match($string_exp, $name)){
  139. $error_message .= 'The name you entered does not appear to be valid.<br/>';
  140. }
  141.  
  142.  
  143. if(strlen($error_message) > 0 ){
  144. died($error_message);
  145. }
  146.  
  147.  
  148. function clean_string($string){
  149. $bad = array("content-type", "bcc:", "to:", "cc:", "href");
  150. return str_replace($bad, "", $string);
  151. }
  152.  
  153.  
  154. //DATABASE SECTION
  155.  
  156. session_start();
  157.  
  158. $user_name = clean_string($name);
  159. $user_email = clean_string($email);
  160.  
  161. if ($user_name == '' || $user_email == '') {
  162.  
  163. echo "<!DOCTYPE html>";
  164. echo "<html>";
  165. echo "<head>";
  166.     echo "<link rel='stylesheet' type='text/css' href='../css/style.css'>";
  167.     echo "<link rel='icon' type='image/ico' href='../images/favicon.ico'>";
  168. echo "</head>";
  169. echo "<body>";
  170.     echo "<div id='maindiv'>";
  171.         echo "<div id='formdiv'>";
  172.             echo "<p>Something went wrong</p>";
  173.         echo "</div>";
  174.     echo "</div>";     
  175. echo "</body>";
  176. echo "</html>";
  177.  
  178. } else {
  179. $_SESSION['user_name2'] = $user_name;
  180. $_SESSION['email_name2'] = $user_email;
  181.  
  182. include '../backend/reg.php';
  183.  
  184. }
  185.  
  186.  
  187.  
  188.  
  189. ?>
  190.  
  191. <!DOCTYPE html>
  192. <html>
  193. <head>
  194.     <link rel="stylesheet" type="text/css" href="../css/style.css">
  195.     <link rel="icon" type="image/ico" href="../images/favicon.ico">
  196. </head>
  197. <body>
  198.     <div id="maindiv">
  199.         <div id="formdiv">
  200.             <p id="thankstext">Thank you for signing up! You're all set to recieve the latest news and information from TEST Pharmaceuticals.</p>
  201.         </div> 
  202.     </div>     
  203. </body>
  204. </html>
  205.  
  206. <?php
  207. }
  208. ?>
Add Comment
Please, Sign In to add comment