Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.11 KB | None | 0 0
  1. <?php
  2. session_start();                                          
  3. switch (@$_POST['Button'])                                
  4. {
  5.   case "Log in":                                        
  6.   include("rmb.php");                                
  7.     $cxn = mysqli_connect($host,$user,$passmilah,$dbase)
  8.              or die("Query died: connect");              
  9.     $sql = "SELECT username FROM user
  10.              WHERE username='$_POST[fusername]'";
  11.     $result = mysqli_query($cxn,$sql)
  12.                 or die("Query died: fusername ");
  13.                 //.mysqli_error($cxn));
  14.     $num = mysqli_num_rows($result);                    
  15.     if($num > 0)  //login name was found                
  16.     {
  17.       $sql = "SELECT username FROM user
  18.              WHERE username='{$_POST['fusername']}'
  19.              AND password='".md5($_POST['fpassword'])."'";
  20.       $result2 = mysqli_query($cxn,$sql)
  21.                    or die(mysqli_error($cxn));      
  22.       $num2 = mysqli_num_rows($result2);                
  23.       if($num2 > 0)  //password matches                  
  24.       {  
  25.         $_SESSION['auth']="yes";                        
  26.         $_SESSION['logname'] = $_POST['fusername'];      
  27.         $sql = "INSERT INTO login (username,logintime)
  28.                 VALUES( '" . $_SESSION [ 'logname' ] . "', NOW() )";
  29.                 //VALUES ($_SESSION[logname],NOW())";
  30.         $result = mysqli_query($cxn,$sql) or die(mysqli_error($cxn));      
  31.         header('Location: home.php');
  32.       }
  33.       else  // password does not match    
  34.         {
  35.         $message_1="The Login Name, '$_POST[fusername]'
  36.                exists, but you have not entered the
  37.                correct password! Please try again.";
  38.         $fusername = strip_tags(trim($_POST['fusername']));
  39.         include("form.php");
  40.       }                                                
  41.     }                                                  
  42.     else  // login name not found                    
  43.     {
  44.       $message_1 = "The User Name you entered does not
  45.                    exist! Please try again.";
  46.       include("form.php");
  47.     }
  48.   break;                                                
  49.  
  50.   case "Register":                                      
  51.    /* Check for blanks */
  52.     foreach($_POST as $field => $value)                
  53.     {
  54.         if(empty($value))
  55.         {
  56.           $blanks[] = $field;
  57.         }
  58.         else
  59.         {
  60.           $good_data[$field] = strip_tags(trim($value));
  61.         }
  62.     }      
  63.    
  64.     //password confirmation VVVV
  65.     if ($password2 != $fpassword)
  66.     {
  67.         $message_1 = "your passwords do not match, please re-type them.";
  68.         echo $password2 . $password;
  69.         foreach($blanks as $value)
  70.         {
  71.             $message_2 .="$value, ";
  72.         }                            
  73.         include("form.php");
  74.         exit();
  75.     }  
  76.     if(isset($blanks))                                  
  77.     {
  78.       $message_2 = "The following fields are blank.
  79.            Please enter the required information:  ";
  80.       foreach($blanks as $value)
  81.       {
  82.         $message_2 .="$value, ";
  83.       }
  84.       extract($good_data);                            
  85.       include("form.php");
  86.       exit();                                          
  87.     }                                                  
  88.   /* validate data */
  89.     foreach($_POST as $field => $value)              
  90.     {
  91.       if(!empty($value))                            
  92.       {
  93.         if(preg_match("/name/i",$field) and
  94.           !preg_match("/user/i",$field) and
  95.           !preg_match("/log/i",$field))
  96.         {
  97.           if (!preg_match("/^[A-Za-z' -]{1,50}$/",$value))
  98.           {
  99.              $errors[] = "$value is not a valid name. ";
  100.           }
  101.         }
  102.         if(preg_match("/street/i",$field) or
  103.            preg_match("/addr/i",$field) or
  104.            preg_match("/city/i",$field))
  105.         {
  106.           if(!preg_match("/^[A-Za-z0-9.,' -]{1,50}$/",
  107.                           $value))
  108.           {
  109.             $errors[] = "$value is not a valid address
  110.                          or city.";
  111.           }
  112.         }
  113.         if(preg_match("/state/i",$field))
  114.         {
  115.           if(!preg_match("/^[A-Z][A-Z]$/",$value))
  116.           {
  117.             $errors[] = "$value is not a valid state code.";
  118.           }
  119.         }
  120.         if(preg_match("/email/i",$field))
  121.         {
  122.           if(!preg_match("/^.+@.+\\..+$/",$value))
  123.           {
  124.             $errors[]="$value is not a valid email address.";
  125.           }
  126.         }
  127.         if(preg_match("/zip/i",$field))
  128.         {
  129.           if(!preg_match("/^[0-9]{5}(\-[0-9]{4})?$/",$value))
  130.           {
  131.             $errors[] = "$value is not a valid zipcode. ";
  132.           }
  133.         }
  134.         if(preg_match("/phone/i",$field) or
  135.            preg_match("/fax/i",$field))
  136.         {
  137.           if(!preg_match("/^[0-9)(xX -]{7,20}$/",$value))
  138.           {
  139.             $errors[]="$value is not a valid phone number.";
  140.           }
  141.         }
  142.       } // end if not empty                            
  143.     }
  144.     foreach($_POST as $field => $value)                
  145.     {
  146.       $$field = strip_tags(trim($value));
  147.     }
  148.     if(@is_array($errors))                        
  149.     {
  150.       $message_2 = "";
  151.       foreach($errors as $value)
  152.       {
  153.         $message_2 .= $value." Please try again<br />";
  154.       }
  155.       include("form.php");
  156.       exit();
  157.     } // end if errors are found                    
  158.  
  159.    /* check to see if user name already exists */
  160.     include("rmb.php");                            
  161.     $cxn = mysqli_connect($host,$user,$passmilah,$dbase)
  162.              or die("Couldn't connect to server");
  163.     $sql = "SELECT username FROM user
  164.                WHERE username='$username'";      
  165.     $result = mysqli_query($cxn,$sql)
  166.                 or die("Query died: username.");
  167.     $num = mysqli_num_rows($result);                    
  168.     if($num > 0)                                      
  169.     {
  170.       $message_2 = "$username already used. Select
  171.                       another User Name.";
  172.       include("form.php");
  173.       exit();
  174.     } // end if user name already exists
  175.     else // Add new user to database              
  176.     {  
  177.       $sql = "INSERT INTO user (username,password,firstName,lastName,email)
  178.         VALUES ('$username',md5('$password'),
  179.               '$firstName', '$lastName','$email')";
  180.       mysqli_query($cxn,$sql);                        
  181.       $_SESSION['auth']="yes";                        
  182.       $_SESSION['logname'] = $username;              
  183.       /* send email to new Customer */
  184.       $emess = "You have successfully registered. ";
  185.       $emess .= "Your new user name and password are: ";
  186.       $emess .= "\n\n\t$username\n\t";
  187.       $emess .= "$password\n\n";
  188.       $emess .= "We appreciate your interest. \n\n";
  189.       $emess .= "If you have any questions or problems,";
  190.       $emess .= " email service@ourstore.com";        
  191.       $subj = "Your new customer registration";    
  192.      # $mailsend=mail("$email","$subj","$emess");      
  193.      header("Location: home.php");            
  194.     }
  195.   break;                                            
  196.  
  197.   default:                                            
  198.     include("form.php");
  199. }  
  200. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement