[ Index ]
 

Code source de osCommerce 2.2ms2-060817

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/catalog/admin/includes/functions/ -> validations.php (source)

   1  <?php
   2  /*
   3    $Id: validations.php,v 1.1 2003/03/15 14:38:38 project3000 Exp $
   4  
   5    osCommerce, Open Source E-Commerce Solutions
   6    http://www.oscommerce.com
   7  
   8    Copyright (c) 2003 osCommerce
   9  
  10    Released under the GNU General Public License
  11  */
  12  
  13    ////////////////////////////////////////////////////////////////////////////////////////////////
  14    //
  15    // Function    : tep_validate_email
  16    //
  17    // Arguments   : email   email address to be checked
  18    //
  19    // Return      : true  - valid email address
  20    //               false - invalid email address
  21    //
  22    // Description : function for validating email address that conforms to RFC 822 specs
  23    //
  24    //               This function is converted from a JavaScript written by
  25    //               Sandeep V. Tamhankar (stamhankar@hotmail.com). The original JavaScript
  26    //               is available at http://javascript.internet.com
  27    //
  28    // Sample Valid Addresses:
  29    //
  30    //    first.last@host.com
  31    //    firstlast@host.to
  32    //    "first last"@host.com
  33    //    "first@last"@host.com
  34    //    first-last@host.com
  35    //    first.last@[123.123.123.123]
  36    //
  37    // Invalid Addresses:
  38    //
  39    //    first last@host.com
  40    //
  41    //
  42    ////////////////////////////////////////////////////////////////////////////////////////////////
  43    function tep_validate_email($email) {
  44      $valid_address = true;
  45  
  46      $mail_pat = '^(.+)@(.+)$';
  47      $valid_chars = "[^] \(\)<>@,;:\.\\\"\[]";
  48      $atom = "$valid_chars+";
  49      $quoted_user='(\"[^\"]*\")';
  50      $word = "($atom|$quoted_user)";
  51      $user_pat = "^$word(\.$word)*$";
  52      $ip_domain_pat='^\[([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\]$';
  53      $domain_pat = "^$atom(\.$atom)*$";
  54  
  55      if (eregi($mail_pat, $email, $components)) {
  56        $user = $components[1];
  57        $domain = $components[2];
  58        // validate user
  59        if (eregi($user_pat, $user)) {
  60          // validate domain
  61          if (eregi($ip_domain_pat, $domain, $ip_components)) {
  62            // this is an IP address
  63              for ($i=1;$i<=4;$i++) {
  64                if ($ip_components[$i] > 255) {
  65                  $valid_address = false;
  66                  break;
  67                }
  68            }
  69          }
  70          else {
  71            // Domain is a name, not an IP
  72            if (eregi($domain_pat, $domain)) {
  73              /* domain name seems valid, but now make sure that it ends in a valid TLD or ccTLD
  74                 and that there's a hostname preceding the domain or country. */
  75              $domain_components = explode(".", $domain);
  76              // Make sure there's a host name preceding the domain.
  77              if (sizeof($domain_components) < 2) {
  78                $valid_address = false;
  79              } else {
  80                $top_level_domain = strtolower($domain_components[sizeof($domain_components)-1]);
  81                // Allow all 2-letter TLDs (ccTLDs)
  82                if (eregi('^[a-z][a-z]$', $top_level_domain) != 1) {
  83                  $tld_pattern = '';
  84                  // Get authorized TLDs from text file
  85                  $tlds = file(DIR_WS_INCLUDES . 'tld.txt');
  86                  while (list(,$line) = each($tlds)) {
  87                    // Get rid of comments
  88                    $words = explode('#', $line);
  89                    $tld = trim($words[0]);
  90                    // TLDs should be 3 letters or more
  91                    if (eregi('^[a-z]{3,}$', $tld) == 1) {
  92                      $tld_pattern .= '^' . $tld . '$|';
  93                    }
  94                  }
  95                  // Remove last '|'
  96                  $tld_pattern = substr($tld_pattern, 0, -1);
  97                  if (eregi("$tld_pattern", $top_level_domain) == 0) {
  98                      $valid_address = false;
  99                  }
 100                }
 101              }
 102            }
 103            else {
 104                $valid_address = false;
 105              }
 106            }
 107        }
 108        else {
 109          $valid_address = false;
 110        }
 111      }
 112      else {
 113        $valid_address = false;
 114      }
 115      if ($valid_address && ENTRY_EMAIL_ADDRESS_CHECK == 'true') {
 116        if (!checkdnsrr($domain, "MX") && !checkdnsrr($domain, "A")) {
 117          $valid_address = false;
 118        }
 119      }
 120      return $valid_address;
 121    }
 122  ?>


Généré le : Mon Nov 26 19:48:25 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics