Ankündigung

Einklappen
Keine Ankündigung bisher.

string mit ampersand auswerten (Gelöst)

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • string mit ampersand auswerten (Gelöst)

    Moin,

    habe leider ein kleines Problem und komme nicht weiter.

    Das Ziel ist nach dem ausfüllen eines Formulars noch vor dem Eintrag in die DB die Daten nach einem bestimmten Wert zu durchsuchen und bei Zutreffen über " $error = true;" eine Fehlermeldung auszugeben. Hier mal ein kleiner Ausschnitt:
    Code:
    $bad_area= array('host', 'port', 'host&port');
    
    if (in_array(strtolower($area), $bad_area)) {
    $error = true;
    Die einfachen Suchbegriffe ohne Sonderzeichen werden problemlos gefunden und als Error übergeben, das & Zeichen treibt mich aber in den Wahnsinn. Habe es bereits mit "host&port" versucht, leider ohne Erfolg.
    Wäre für jede Hilfe oder Hinweis der zur Lösung meines Problems führt, äußerst dankbar.

    Gruß

  • #2
    Lösch mal Deinen gesamten Beitrag inkl. Überschrift und schreibe den mal neu. Weder die Überschrift noch Deine Sätze oder der Quellcode ergeben Sinn.
    bitcoin.de <- Meine Freelancerwährung

    Kommentar


    • #3
      Bitte immer nachvollziehbaren Testcode liefern. Deiner ist unvollständig und nicht testbar. Man kann also nicht sehen, was da falsch läuft.

      Kommentar


      • #4
        Kannst du mir einen Hinweis geben was an meiner Anfrage falsch ist?

        die Übergabe aus dem Formular sieht so aus:

        Code:
        if (AREA == 'true') $area= tep_db_prepare_input($HTTP_POST_VARS['area']);
        Den Übergabewert "area" versuche ich zu filtern, dies gelingt ja auch soweit. Sobald aber ein & im Wert vorhanden ist, wird der Wert nicht mehr beachtet.

        Kommentar


        • #5
          $HTTP_POST_VARS gibts schon seit fast 20 Jahren nicht mehr. Wo hast du diesen uralten Code ausgegraben? Bitte tu sowas nicht.

          Kommentar


          • #6
            Ich möchte da ja nur einen Filter setzen und damit falsche Daten sofort mit einer Fehlermeldung blockieren. Den Code habe ich nun mal und bin derzeit noch darauf angewiesen.

            In etwa so sieht es dann im Einsatz aus:

            Code:
            if (isset($HTTP_POST_VARS['action']) && ($HTTP_POST_VARS['action'] == 'process')) {
                $process = true;
            
                if (ACCOUNT_GENDER == 'true') {
                  if (isset($HTTP_POST_VARS['gender'])) {
                    $gender = tep_db_prepare_input($HTTP_POST_VARS['gender']);
                  } else {
                    $gender = false;
                  }
                }
                $firstname = tep_db_prepare_input($HTTP_POST_VARS['firstname']);
                $lastname = tep_db_prepare_input($HTTP_POST_VARS['lastname']);
                if (ACCOUNT_DOB == 'true') $dob = tep_db_prepare_input($HTTP_POST_VARS['dob']);
                $email_address = tep_db_prepare_input($HTTP_POST_VARS['email_address']);
                if (ACCOUNT_COMPANY == 'true') $company = tep_db_prepare_input($HTTP_POST_VARS['company']);
                $street_address = tep_db_prepare_input($HTTP_POST_VARS['street_address']);
                $area = tep_db_prepare_input($HTTP_POST_VARS['area']);
                if (ACCOUNT_SUBURB == 'true') $suburb = tep_db_prepare_input($HTTP_POST_VARS['suburb']);
                $postcode = tep_db_prepare_input($HTTP_POST_VARS['postcode']);
                $city = tep_db_prepare_input($HTTP_POST_VARS['city']);
                if (ACCOUNT_STATE == 'true') {
                  $state = tep_db_prepare_input($HTTP_POST_VARS['state']);
                  if (isset($HTTP_POST_VARS['zone_id'])) {
                    $zone_id = tep_db_prepare_input($HTTP_POST_VARS['zone_id']);
                  } else {
                    $zone_id = false;
                  }
                }
                $country = tep_db_prepare_input($HTTP_POST_VARS['country']);
                $telephone = tep_db_prepare_input($HTTP_POST_VARS['telephone']);
                $fax = tep_db_prepare_input($HTTP_POST_VARS['fax']);
                $handy = tep_db_prepare_input($HTTP_POST_VARS['handy']);
            
                if (isset($HTTP_POST_VARS['newsletter'])) {
                  $newsletter = tep_db_prepare_input($HTTP_POST_VARS['newsletter']);
                } else {
                  $newsletter = false;
                }
                if (isset($HTTP_POST_VARS['group'])) {
                  $group = tep_db_prepare_input($HTTP_POST_VARS['group']);
                  if($group != '1') {
                    $c_status = '0';
                  }
                  else {
                    $c_status = '1';
                  }
            
                } else {
                  $group = '1';
                  $c_status = '0';
            
                }  
                $password = tep_db_prepare_input($HTTP_POST_VARS['password']);
                $confirmation = tep_db_prepare_input($HTTP_POST_VARS['confirmation']);
            
                $error = false;
            
            $bad_area = array(port, host, 'AT', 'port&host' );  
            
               if (in_array(strtolower($area), $bad_area)) {
                $error = true;
                 $messageStack->add('create_account', ENTRY_OF_AREA_ERROR);
                }

            Kommentar


            • #7
              Nimm den hier zum testen und lerne was daraus

              PHP-Code:
              <?php
              header
              ('Content-Type: text/html; charset=utf-8');

              $error null;  
              $bad_words = array('host''port''host&port');

              if ( isset(
              $_POST['submit'], $_POST['area']) ){

                  
              $words preg_split("/[\s,]+/u"$_POST['area']);

                  foreach( 
              $words as $word ){

                      if ( 
              in_arraystrtolower($word), $bad_words ) ) {
                          
              $error .= "Fehler: '" htmlspecialchars($wordENT_QUOTES ENT_HTML5'UTF-8') . "' nicht erlaubt. <br>";
                      }
                  }
              }
              ?>

              <!DOCTYPE html>
              <html lang="de">
              <head>
                  <meta charset="UTF-8">
                  <title>Test</title>
                  <style>
                  form *{display: block;}
                  </style>
              </head>

              <body>
                 <p><?= $error?></p>
                 <form method="post">
                     <textarea name="area" cols="40" rows="10">Lorem host&port Ipsum
              Ähh host ist verboten
              und port ebenso?</textarea>
                     <button name="submit">absenden</button>
                 </form>
              </body>
              </html>
              Im Handbuch zu finden:
              preg_split
              htmlspecialchars

              Kommentar


              • #8
                Und was steht in $area drin?

                Davon abgesehen hast du immer noch keinen testbaren Code geliefert. Wenn du nicht gewillt bist mitzuarbeiten, dann bist du in einem Forum falsch und du solltest dir eher einen Programmierer suchen, der das gegen Bezahlung für dich macht.

                Kommentar


                • #9
                  Der Wert $area ist nur als Platzhalter für ein Testcode gewählt. Hier der Vollständige Code, dabei wird der Wert $company ausgewertet.

                  PHP-Code:
                  <?php


                    
                  require('includes/application_top.php');

                  // needs to be included earlier to set the success message in the messageStack
                    
                  require(DIR_WS_LANGUAGES $language '/' FILENAME_CREATE_ACCOUNT);

                    
                  $process false;
                    if (isset(
                  $HTTP_POST_VARS['action']) && ($HTTP_POST_VARS['action'] == 'process')) {
                      
                  $process true;

                      if (
                  ACCOUNT_GENDER == 'true') {
                        if (isset(
                  $HTTP_POST_VARS['gender'])) {
                          
                  $gender tep_db_prepare_input($HTTP_POST_VARS['gender']);
                        } else {
                          
                  $gender false;
                        }
                      }
                      
                  $firstname tep_db_prepare_input($HTTP_POST_VARS['firstname']);
                      
                  $lastname tep_db_prepare_input($HTTP_POST_VARS['lastname']);
                      if (
                  ACCOUNT_DOB == 'true'$dob tep_db_prepare_input($HTTP_POST_VARS['dob']);
                      
                  $email_address tep_db_prepare_input($HTTP_POST_VARS['email_address']);
                      if (
                  ACCOUNT_COMPANY == 'true'$company tep_db_prepare_input($HTTP_POST_VARS['company']);
                      
                  $street_address tep_db_prepare_input($HTTP_POST_VARS['street_address']);
                      if (
                  ACCOUNT_SUBURB == 'true'$suburb tep_db_prepare_input($HTTP_POST_VARS['suburb']);
                      
                  $postcode tep_db_prepare_input($HTTP_POST_VARS['postcode']);
                      
                  $city tep_db_prepare_input($HTTP_POST_VARS['city']);
                      if (
                  ACCOUNT_STATE == 'true') {
                        
                  $state tep_db_prepare_input($HTTP_POST_VARS['state']);
                        if (isset(
                  $HTTP_POST_VARS['zone_id'])) {
                          
                  $zone_id tep_db_prepare_input($HTTP_POST_VARS['zone_id']);
                        } else {
                          
                  $zone_id false;
                        }
                      }
                      
                  $country tep_db_prepare_input($HTTP_POST_VARS['country']);
                      
                  $telephone tep_db_prepare_input($HTTP_POST_VARS['telephone']);
                      
                  $fax tep_db_prepare_input($HTTP_POST_VARS['fax']);
                      
                  $handy tep_db_prepare_input($HTTP_POST_VARS['handy']);

                      if (isset(
                  $HTTP_POST_VARS['newsletter'])) {
                        
                  $newsletter tep_db_prepare_input($HTTP_POST_VARS['newsletter']);
                      } else {
                        
                  $newsletter false;
                      }
                      if (isset(
                  $HTTP_POST_VARS['group'])) {
                        
                  $group tep_db_prepare_input($HTTP_POST_VARS['group']);
                        if(
                  $group != '1') {
                          
                  $c_status '0';
                        }
                        else {
                          
                  $c_status '1';
                        }

                      } else {
                        
                  $group '1';
                        
                  $c_status '0';

                      }    
                      
                  $password tep_db_prepare_input($HTTP_POST_VARS['password']);
                      
                  $confirmation tep_db_prepare_input($HTTP_POST_VARS['confirmation']);

                      
                  $error false;

                  //Added to block spammers A

                  $bad_companies = array('google''apple''AT''AT&T''AT&amp;T' );    

                     if (
                  in_array(strtolower($company), $bad_companies)) {
                      
                  $error true;
                        
                  $messageStack->add('create_account'"Sie haben Spam-Präventionsregeln ausgelöst. Wenn Ihre Angaben korrekt sind und Sie kein Spammer sind, kontaktieren Sie uns bitte oder versuchen Sie es erneut.");
                        
                  $spam_email_text "Verwendeter Name: <b>" $firstname " " $lastname "</b> Verwendeter Firmenname:<b> ".$company "</b> : Ausgelöster Spam-Alarm.";
                        
                  tep_mail(STORE_OWNERSTORE_OWNER_EMAIL_ADDRESS'BOT Spammer Alarm!'$spam_email_textSTORE_OWNERSTORE_OWNER_EMAIL_ADDRESS);
                      }
                  //Added to block spammers A


                      
                  if (ACCOUNT_GENDER == 'true') {
                        if ( (
                  $gender != 'm') && ($gender != 'f') ) {
                          
                  $error true;

                          
                  $messageStack->add('create_account'ENTRY_GENDER_ERROR);
                        }
                      }

                      if (
                  strlen($firstname) < ENTRY_FIRST_NAME_MIN_LENGTH) {
                        
                  $error true;

                        
                  $messageStack->add('create_account'ENTRY_FIRST_NAME_ERROR);
                      }

                      if (
                  strlen($lastname) < ENTRY_LAST_NAME_MIN_LENGTH) {
                        
                  $error true;

                        
                  $messageStack->add('create_account'ENTRY_LAST_NAME_ERROR);
                      }

                      if (
                  ACCOUNT_DOB == 'true') {
                        if (
                  checkdate(substr(tep_date_raw($dob), 42), substr(tep_date_raw($dob), 62), substr(tep_date_raw($dob), 04)) == false) {
                          
                  $error true;

                          
                  $messageStack->add('create_account'ENTRY_DATE_OF_BIRTH_ERROR);
                        }
                      }

                      if (
                  strlen($email_address) < ENTRY_EMAIL_ADDRESS_MIN_LENGTH) {
                        
                  $error true;

                        
                  $messageStack->add('create_account'ENTRY_EMAIL_ADDRESS_ERROR);
                      } elseif (
                  tep_validate_email($email_address) == false) {
                        
                  $error true;

                        
                  $messageStack->add('create_account'ENTRY_EMAIL_ADDRESS_CHECK_ERROR);
                      } else {
                        
                  $check_email_query tep_db_query("select count(*) as total from " TABLE_CUSTOMERS " where customers_email_address = '" tep_db_input($email_address) . "'");
                        
                  $check_email tep_db_fetch_array($check_email_query);
                        if (
                  $check_email['total'] > 0) {
                          
                  $error true;

                          
                  $messageStack->add('create_account'ENTRY_EMAIL_ADDRESS_ERROR_EXISTS);
                        }
                      }

                      if (
                  strlen($street_address) < ENTRY_STREET_ADDRESS_MIN_LENGTH) {
                        
                  $error true;

                        
                  $messageStack->add('create_account'ENTRY_STREET_ADDRESS_ERROR);
                      }

                      if (
                  strlen($postcode) < ENTRY_POSTCODE_MIN_LENGTH) {
                        
                  $error true;

                        
                  $messageStack->add('create_account'ENTRY_POST_CODE_ERROR);
                      }

                      if (
                  strlen($city) < ENTRY_CITY_MIN_LENGTH) {
                        
                  $error true;

                        
                  $messageStack->add('create_account'ENTRY_CITY_ERROR);
                      }

                      if (
                  is_numeric($country) == false) {
                        
                  $error true;

                        
                  $messageStack->add('create_account'ENTRY_COUNTRY_ERROR);
                      }

                      if (
                  ACCOUNT_STATE == 'true') {
                        
                  $zone_id 0;
                        
                  $check_query tep_db_query("select count(*) as total from " TABLE_ZONES " where zone_country_id = '" . (int)$country "'");
                        
                  $check tep_db_fetch_array($check_query);
                        
                  $entry_state_has_zones = ($check['total'] > 0);
                        if (
                  $entry_state_has_zones == true) {
                          
                  $zone_query tep_db_query("select distinct zone_id from " TABLE_ZONES " where zone_country_id = '" . (int)$country "' and (zone_name like '" tep_db_input($state) . "%' or zone_code like '%" tep_db_input($state) . "%')");
                          if (
                  tep_db_num_rows($zone_query) == 1) {
                            
                  $zone tep_db_fetch_array($zone_query);
                            
                  $zone_id $zone['zone_id'];
                          } else {
                            
                  $error true;

                            
                  $messageStack->add('create_account'ENTRY_STATE_ERROR_SELECT);
                          }
                        } else {
                          if (
                  strlen($state) < ENTRY_STATE_MIN_LENGTH) {
                            
                  $error true;

                            
                  $messageStack->add('create_account'ENTRY_STATE_ERROR);
                          }
                        }
                      }

                      if (
                  strlen($telephone) < ENTRY_TELEPHONE_MIN_LENGTH) {
                        
                  $error true;

                        
                  $messageStack->add('create_account'ENTRY_TELEPHONE_NUMBER_ERROR);
                      }


                      if (
                  strlen($password) < ENTRY_PASSWORD_MIN_LENGTH) {
                        
                  $error true;

                        
                  $messageStack->add('create_account'ENTRY_PASSWORD_ERROR);
                      } elseif (
                  $password != $confirmation) {
                        
                  $error true;

                        
                  $messageStack->add('create_account'ENTRY_PASSWORD_ERROR_NOT_MATCHING);
                      }

                      if (
                  $error == false) {
                        
                  $sql_data_array = array('customers_firstname' => $firstname,
                                                
                  'customers_lastname' => $lastname,
                                                
                  'customers_email_address' => $email_address,
                                                
                  'customers_telephone' => $telephone,
                                                
                  'customers_fax' => $fax,
                                                
                  'customers_handy' => $handy,                              
                                                
                  'customers_newsletter' => $newsletter,
                                                
                  'customers_password' => tep_encrypt_password($password),
                                                
                  'customers_groups_id' => $group,
                                                
                  'customers_status' => $c_status);

                        if (
                  ACCOUNT_GENDER == 'true'$sql_data_array['customers_gender'] = $gender;
                        if (
                  ACCOUNT_DOB == 'true'$sql_data_array['customers_dob'] = tep_date_raw($dob);

                        
                  tep_db_perform(TABLE_CUSTOMERS$sql_data_array);

                        
                  $customer_id tep_db_insert_id();

                        
                  $sql_data_array = array('customers_id' => $customer_id,
                                                
                  'entry_firstname' => $firstname,
                                                
                  'entry_lastname' => $lastname,
                                                
                  'entry_street_address' => $street_address,
                                                
                  'entry_postcode' => $postcode,
                                                
                  'entry_city' => $city,
                                                
                  'entry_country_id' => $country);

                        if (
                  ACCOUNT_GENDER == 'true'$sql_data_array['entry_gender'] = $gender;
                        if (
                  ACCOUNT_COMPANY == 'true'$sql_data_array['entry_company'] = $company;
                        if (
                  ACCOUNT_SUBURB == 'true'$sql_data_array['entry_suburb'] = $suburb;
                        if (
                  ACCOUNT_STATE == 'true') {
                          if (
                  $zone_id 0) {
                            
                  $sql_data_array['entry_zone_id'] = $zone_id;
                            
                  $sql_data_array['entry_state'] = '';
                          } else {
                            
                  $sql_data_array['entry_zone_id'] = '0';
                            
                  $sql_data_array['entry_state'] = $state;
                          }
                        }

                        
                  tep_db_perform(TABLE_ADDRESS_BOOK$sql_data_array);

                        
                  $address_id tep_db_insert_id();

                        
                  tep_db_query("update " TABLE_CUSTOMERS " set customers_default_address_id = '" . (int)$address_id "' where customers_id = '" . (int)$customer_id "'");

                        
                  tep_db_query("insert into " TABLE_CUSTOMERS_INFO " (customers_info_id, customers_info_number_of_logons, customers_info_date_account_created) values ('" . (int)$customer_id "', '0', now())");

                        if (
                  SESSION_RECREATE == 'True') {
                          
                  tep_session_recreate();
                        }

                        
                  $customer_first_name $firstname;
                        
                  $customer_default_address_id $address_id;
                        
                  $customer_country_id $country;
                        
                  $customer_zone_id $zone_id;
                        
                  tep_session_register('customer_id');
                        
                  tep_session_register('customer_first_name');
                        
                  tep_session_register('customer_default_address_id');
                        
                  tep_session_register('customer_country_id');
                        
                  tep_session_register('customer_zone_id');

                  // restore cart contents
                        
                  $cart->restore_contents();

                  // build the message content
                        
                  $name $firstname ' ' $lastname;

                        if (
                  ACCOUNT_GENDER == 'true') {
                           if (
                  $gender == 'm') {
                             
                  $email_text sprintf(EMAIL_GREET_MR$lastname);
                           } else {
                             
                  $email_text sprintf(EMAIL_GREET_MS$lastname);
                           }
                        } else {
                          
                  $email_text sprintf(EMAIL_GREET_NONE$firstname);
                        }

                        
                  $email_text .= EMAIL_WELCOME EMAIL_TEXT EMAIL_CONTACT EMAIL_WARNING;
                        
                  tep_mail($name$email_addressEMAIL_SUBJECT$email_textSTORE_OWNERSTORE_OWNER_EMAIL_ADDRESS);

                        if(
                  $group != '1') {  
                  //TotalB2B start
                        
                  $email_validate_text EMAIL_VALIDATE " \n\n " EMAIL_VALIDATE_PROFILE " " tep_href_link('admin/customers.php','cID='.$customer_id.'&action=edit''SSL') . " \n" EMAIL_VALIDATE_ACTIVATE " " tep_href_link('admin/customers.php','action=setflag&flag=1&cID='.$customer_id'SSL');
                        
                  tep_mail(STORE_OWNERSTORE_OWNER_EMAIL_ADDRESSEMAIL_VALIDATE_SUBJECT$email_validate_textSTORE_OWNERSTORE_OWNER_EMAIL_ADDRESS);
                  //TotalB2B end
                        
                  }
                        
                  tep_redirect(tep_href_link(FILENAME_CREATE_ACCOUNT_SUCCESS'''SSL'));
                      }
                    }

                    
                  $breadcrumb->add(NAVBAR_TITLEtep_href_link(FILENAME_CREATE_ACCOUNT'''SSL'));

                    
                  $content CONTENT_CREATE_ACCOUNT;
                    
                  $javascript 'form_check.js.php';
                    include (
                  bts_select('main'$content_template)); // BTSv1.5

                    
                  require(DIR_WS_INCLUDES 'application_bottom.php');
                  ?>

                  Kommentar


                  • #10
                    Bitte einen kurzen und knackigen Testcode posten, der bei jedem anderen außer dir auch läuft. Mit dem Code hier fangt keiner was an.

                    Kommentar


                    • #11
                      ok, Danke für den Hinweis. Hier mal ein knapper Beispiel:

                      So funktioniert der Code:
                      Code:
                      <?php
                      
                      $company = 'google';
                      
                      $bad_companies = array('google', 'apple', 'AT', 'AT&T', 'AT&amp;T' );
                      
                      
                      if (in_array(strtolower($company), $bad_companies)) {
                          $error = true;
                      echo ('Fehler');    
                      
                      }
                      ?>
                      Sobald aber ein & Zeichen im Wert vorhanden ist, bekomme ich keine Ausgabe:

                      Code:
                      <?php
                      
                      $company = 'AT&T';
                      
                      $bad_companies = array('google', 'apple', 'AT', 'AT&T', 'AT&amp;T' );
                      
                      
                      if (in_array(strtolower($company), $bad_companies)) {
                          $error = true;
                      echo ('Fehler');    
                      
                      }
                      ?>

                      Kommentar


                      • #12
                        PHP-Code:
                         <?php  
                        $company 
                        'AT';  
                        $bad_companies = array('google''apple''AT''AT&T''AT&amp;T' );  
                        if (
                        in_array(strtolower($company), $bad_companies)) {    
                            
                        $error true;
                            echo (
                        'Fehler');    
                        }
                        ?>
                        Das geht auch nicht.

                        Es liegt nicht am & sondern am strtolower.

                        Kommentar


                        • #13
                          Siehe #7 als funktionierendes Beispiel.

                          Kommentar


                          • #14
                            Die Firma heisst auch AT&T und nicht AT&amp;T.
                            ich behaupte aber es liegt an der groß und kleinschreibung, nicht am &,
                            wie schon so viele vor mir ...

                            Kommentar


                            • #15
                              OK, vielen Dank für den entscheidenden Hinweis, es lag tatsächlich am strtolower. Da dadurch die $company in Kleinschreibung übergeben wird, müssen die Suchbegriffe unter $bad_companies alle in klein eingetragen werden.

                              Code:
                              <?php
                              
                              $company = 'AT&T';
                              
                              $bad_companies = array('google', 'apple', 'at&t' );
                              
                              
                              if (in_array(strtolower($company), $bad_companies)) {
                                  $error = true;
                              echo ('Fehler');    
                              
                              }
                              ?>

                              Kommentar

                              Lädt...
                              X