Advertisement
Guest User

Untitled

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