Ignore:
Timestamp:
Nov 26, 2007 11:30:12 PM (17 years ago)
Author:
quinn
Message:

Fixed getRemoteAddr() to return only one value of a comma-delimited list.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Utilities.inc.php

    r282 r290  
    849849{
    850850    $ip = getenv('HTTP_CLIENT_IP');
    851     if (empty($ip) || $ip == 'unknown' || $ip == 'localhost' || $ip == '127.0.0.1') {
     851    if (in_array($ip, array('', 'unknown', 'localhost', '127.0.0.1'))) {
    852852        $ip = getenv('HTTP_X_FORWARDED_FOR');
    853         if (empty($ip) || $ip == 'unknown' || $ip == 'localhost' || $ip == '127.0.0.1') {
     853        if (mb_strpos($ip, ',') !== false) {
     854            // If HTTP_X_FORWARDED_FOR returns a comma-delimited list of IPs then return the first one (assuming the first is the original).
     855            $ips = explode(',', $ip, 2);
     856            $ip = $ips[0];
     857        }
     858        if (in_array($ip, array('', 'unknown', 'localhost', '127.0.0.1'))) {
    854859            $ip = getenv('REMOTE_ADDR');
    855860        }
Note: See TracChangeset for help on using the changeset viewer.