/[drupal]/contributions/modules/drupalvb/drupalvb.inc.php
ViewVC logotype

Diff of /contributions/modules/drupalvb/drupalvb.inc.php

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.9.4.25.2.3, Wed Jul 29 17:38:01 2009 UTC revision 1.9.4.25.2.4, Wed Jul 29 17:43:20 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: drupalvb.inc.php,v 1.9.4.25.2.2 2009/06/05 15:03:20 sun Exp $  // $Id: drupalvb.inc.php,v 1.9.4.25.2.3 2009/07/29 17:38:01 sun Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 112  function drupalvb_get_ip() { Line 112  function drupalvb_get_ip() {
112      $ip = $_SERVER['HTTP_CLIENT_IP'];      $ip = $_SERVER['HTTP_CLIENT_IP'];
113    }    }
114    else if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) {    else if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) {
115      // Make sure we don't pick up an internal IP defined by RFC1918.      // Try to avoid using an internal IP address, it's probably a proxy.
116      foreach ($matches[0] as $match) {      $ranges = array(
117        if (!preg_match("#^(10|172\.16|192\.168)\.#", $match)) {        '10.0.0.0/8' => array(ip2long('10.0.0.0'), ip2long('10.255.255.255')),
118          $ip = $match;        '127.0.0.0/8' => array(ip2long('127.0.0.0'), ip2long('127.255.255.255')),
119          '169.254.0.0/16' => array(ip2long('169.254.0.0'), ip2long('169.254.255.255')),
120          '172.16.0.0/12' => array(ip2long('172.16.0.0'), ip2long('172.31.255.255')),
121          '192.168.0.0/16' => array(ip2long('192.168.0.0'), ip2long('192.168.255.255')),
122        );
123        foreach ($matches[0] as $_ip) {
124          $ip_long = ip2long($_ip);
125          if ($ip_long === FALSE || $ip_long == -1) {
126            continue;
127          }
128    
129          $private_ip = FALSE;
130          foreach ($ranges as $range) {
131            if ($ip_long >= $range[0] && $ip_long <= $range[1]) {
132              $private_ip = TRUE;
133              break;
134            }
135          }
136    
137          if (!$private_ip) {
138            $ip = $_ip;
139          break;          break;
140        }        }
141      }      }

Legend:
Removed from v.1.9.4.25.2.3  
changed lines
  Added in v.1.9.4.25.2.4

  ViewVC Help
Powered by ViewVC 1.1.2