[ PHPXref.com ] [ Generated: Sun Jul 20 19:13:40 2008 ] [ osCommRes 1.2.0 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

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

   1  <?php
   2  /*

   3  

   4    osCommerce, Open Source E-Commerce Solutions

   5    http://www.oscommerce.com

   6  

   7    Copyright (c) 2003 osCommerce

   8    

   9    osCommRes, Services Online

  10    http://www.oscommres.com

  11  

  12    Copyright (c) 2005 osCommRes

  13  

  14    Released under the GNU General Public License

  15  */
  16    ////////////////////////////////////////////////////////////////////////////////////////////////

  17    //

  18    // Function    : tep_validate_email

  19    //

  20    // Arguments   : email   email address to be checked

  21    //

  22    // Return      : true  - valid email address

  23    //               false - invalid email address

  24    //

  25    // Description : function for validating email address that conforms to RFC 822 specs

  26    //

  27    //               This function is converted from a JavaScript written by

  28    //               Sandeep V. Tamhankar (stamhankar@hotmail.com). The original JavaScript

  29    //               is available at http://javascript.internet.com

  30    //

  31    // Sample Valid Addresses:

  32    //

  33    //    first.last@host.com

  34    //    firstlast@host.to

  35    //    "first last"@host.com

  36    //    "first@last"@host.com

  37    //    first-last@host.com

  38    //    first.last@[123.123.123.123]

  39    //

  40    // Invalid Addresses:

  41    //

  42    //    first last@host.com

  43    //

  44    //

  45    ////////////////////////////////////////////////////////////////////////////////////////////////

  46    function tep_validate_email($email) {
  47      $valid_address = true;
  48  
  49      $mail_pat = '^(.+)@(.+)$';
  50      $valid_chars = "[^] \(\)<>@,;:\.\\\"\[]";
  51      $atom = "$valid_chars+";
  52      $quoted_user='(\"[^\"]*\")';
  53      $word = "($atom|$quoted_user)";
  54      $user_pat = "^$word(\.$word)*$";
  55      $ip_domain_pat='^\[([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\]$';
  56      $domain_pat = "^$atom(\.$atom)*$";
  57  
  58      if (eregi($mail_pat, $email, $components)) {
  59        $user = $components[1];
  60        $domain = $components[2];
  61        // validate user

  62        if (eregi($user_pat, $user)) {
  63          // validate domain

  64          if (eregi($ip_domain_pat, $domain, $ip_components)) {
  65            // this is an IP address

  66              for ($i=1;$i<=4;$i++) {
  67                if ($ip_components[$i] > 255) {
  68                  $valid_address = false;
  69                  break;
  70                }
  71            }
  72          }
  73          else {
  74            // Domain is a name, not an IP

  75            if (eregi($domain_pat, $domain)) {
  76              /* domain name seems valid, but now make sure that it ends in a valid TLD or ccTLD

  77                 and that there's a hostname preceding the domain or country. */
  78              $domain_components = explode(".", $domain);
  79              // Make sure there's a host name preceding the domain.

  80              if (sizeof($domain_components) < 2) {
  81                $valid_address = false;
  82              } else {
  83                $top_level_domain = strtolower($domain_components[sizeof($domain_components)-1]);
  84                // Allow all 2-letter TLDs (ccTLDs)

  85                if (eregi('^[a-z][a-z]$', $top_level_domain) != 1) {
  86                  $tld_pattern = '';
  87                  // Get authorized TLDs from text file

  88                  $tlds = file(DIR_WS_INCLUDES . 'tld.txt');
  89                  while (list(,$line) = each($tlds)) {
  90                    // Get rid of comments

  91                    $words = explode('#', $line);
  92                    $tld = trim($words[0]);
  93                    // TLDs should be 3 letters or more

  94                    if (eregi('^[a-z]{3,}$', $tld) == 1) {
  95                      $tld_pattern .= '^' . $tld . '$|';
  96                    }
  97                  }
  98                  // Remove last '|'

  99                  $tld_pattern = substr($tld_pattern, 0, -1);
 100                  if (eregi("$tld_pattern", $top_level_domain) == 0) {
 101                      $valid_address = false;
 102                  }
 103                }
 104              }
 105            }
 106            else {
 107                $valid_address = false;
 108              }
 109            }
 110        }
 111        else {
 112          $valid_address = false;
 113        }
 114      }
 115      else {
 116        $valid_address = false;
 117      }
 118      if ($valid_address && ENTRY_EMAIL_ADDRESS_CHECK == 'true') {
 119        if (!checkdnsrr($domain, "MX") && !checkdnsrr($domain, "A")) {
 120          $valid_address = false;
 121        }
 122      }
 123      return $valid_address;
 124    }
 125  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]