Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2017
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.05 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 != $_POST['fpassword'])
  66.     {
  67.         $message_2 = "your passwords do not match, please re-type them.";
  68.         //echo $password2 . $password;                          
  69.         include("form.php");
  70.         exit();
  71.     }  
  72.     if(isset($blanks))                                  
  73.     {
  74.       $message_2 = "The following fields are blank.
  75.            Please enter the required information:  ";
  76.       foreach($blanks as $value)
  77.       {
  78.         $message_2 .="$value, ";
  79.       }
  80.       extract($good_data);                            
  81.       include("form.php");
  82.       exit();                                          
  83.     }                                                  
  84.   /* validate data */
  85.     foreach($_POST as $field => $value)              
  86.     {
  87.       if(!empty($value))                            
  88.       {
  89.         if(preg_match("/name/i",$field) and
  90.           !preg_match("/user/i",$field) and
  91.           !preg_match("/log/i",$field))
  92.         {
  93.           if (!preg_match("/^[A-Za-z' -]{1,50}$/",$value))
  94.           {
  95.              $errors[] = "$value is not a valid name. ";
  96.           }
  97.         }
  98.         if(preg_match("/street/i",$field) or
  99.            preg_match("/addr/i",$field) or
  100.            preg_match("/city/i",$field))
  101.         {
  102.           if(!preg_match("/^[A-Za-z0-9.,' -]{1,50}$/",
  103.                           $value))
  104.           {
  105.             $errors[] = "$value is not a valid address
  106.                          or city.";
  107.           }
  108.         }
  109.         if(preg_match("/state/i",$field))
  110.         {
  111.           if(!preg_match("/^[A-Z][A-Z]$/",$value))
  112.           {
  113.             $errors[] = "$value is not a valid state code.";
  114.           }
  115.         }
  116.         if(preg_match("/email/i",$field))
  117.         {
  118.           if(!preg_match("/^.+@.+\\..+$/",$value))
  119.           {
  120.             $errors[]="$value is not a valid email address.";
  121.           }
  122.         }
  123.         if(preg_match("/zip/i",$field))
  124.         {
  125.           if(!preg_match("/^[0-9]{5}(\-[0-9]{4})?$/",$value))
  126.           {
  127.             $errors[] = "$value is not a valid zipcode. ";
  128.           }
  129.         }
  130.         if(preg_match("/phone/i",$field) or
  131.            preg_match("/fax/i",$field))
  132.         {
  133.           if(!preg_match("/^[0-9)(xX -]{7,20}$/",$value))
  134.           {
  135.             $errors[]="$value is not a valid phone number.";
  136.           }
  137.         }
  138.       } // end if not empty                            
  139.     }
  140.     foreach($_POST as $field => $value)                
  141.     {
  142.       $$field = strip_tags(trim($value));
  143.     }
  144.     if(@is_array($errors))                        
  145.     {
  146.       $message_2 = "";
  147.       foreach($errors as $value)
  148.       {
  149.         $message_2 .= $value." Please try again<br />";
  150.       }
  151.       include("form.php");
  152.       exit();
  153.     } // end if errors are found                    
  154.  
  155.    /* check to see if user name already exists */
  156.     include("rmb.php");                            
  157.     $cxn = mysqli_connect($host,$user,$passmilah,$dbase)
  158.              or die("Couldn't connect to server");
  159.     $sql = "SELECT username FROM user
  160.                WHERE username='$username'";      
  161.     $result = mysqli_query($cxn,$sql)
  162.                 or die("Query died: username.");
  163.     $num = mysqli_num_rows($result);                    
  164.     if($num > 0)                                      
  165.     {
  166.       $message_2 = "$username already used. Select
  167.                       another User Name.";
  168.       include("form.php");
  169.       exit();
  170.     } // end if user name already exists
  171.     else // Add new user to database              
  172.     {  
  173.       $sql = "INSERT INTO user (username,password,firstName,lastName,email)
  174.         VALUES ('$username',md5('$password'),
  175.               '$firstName', '$lastName','$email')";
  176.       mysqli_query($cxn,$sql);                        
  177.       $_SESSION['auth']="yes";                        
  178.       $_SESSION['logname'] = $username;              
  179.       /* send email to new Customer */
  180.       $emess = "You have successfully registered. ";
  181.       $emess .= "Your new user name and password are: ";
  182.       $emess .= "\n\n\t$username\n\t";
  183.       $emess .= "$password\n\n";
  184.       $emess .= "We appreciate your interest. \n\n";
  185.       $emess .= "If you have any questions or problems,";
  186.       $emess .= " email service@ourstore.com";        
  187.       $subj = "Your new customer registration";    
  188.      # $mailsend=mail("$email","$subj","$emess");      
  189.      header("Location: home.php");            
  190.     }
  191.   break;                                            
  192.  
  193.   default:                                            
  194.     include("form.php");
  195. }  
  196. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement