You are here

function _uc_file_ip_address in Ubercart 5

1 call to _uc_file_ip_address()
_file_download in uc_file/uc_file.module
Perform first-pass authorization. Call authorization hooks afterwards.

File

uc_file/uc_file.module, line 991
Allows products to be associated with downloadable files.

Code

function _uc_file_ip_address() {
  static $ip_address = NULL;
  if (!isset($ip_address)) {
    $ip_address = $_SERVER['REMOTE_ADDR'];
    if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {

      // If an array of known reverse proxy IPs is provided, then trust
      // the XFF header if request really comes from one of them.
      $reverse_proxy_addresses = variable_get('uc_file_reverse_proxy_addresses', array());
      if (!empty($reverse_proxy_addresses) && in_array($ip_address, $reverse_proxy_addresses, TRUE)) {

        // If there are several arguments, we need to check the most
        // recently added one, i.e. the last one.
        $ip_address = array_pop(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']));
      }
    }
  }
  return $ip_address;
}