Quote Originally Posted by lat9 View Post
@mc12345678, the documentation for filter_val indicates that the options are either an array or a bitwise disjunction of values (as I supplied). I'll bite that all the default values should be used, so the change should be
Code:
 function zen_get_ip_address() {
    $ip = '';
    /**
     * resolve any proxies
     */
    if (isset($_SERVER)) {
      if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
      } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
        $ip = $_SERVER['HTTP_CLIENT_IP'];
      } elseif (isset($_SERVER['HTTP_X_FORWARDED'])) {
        $ip = $_SERVER['HTTP_X_FORWARDED'];
      } elseif (isset($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) {
        $ip = $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
      } elseif (isset($_SERVER['HTTP_FORWARDED_FOR'])) {
        $ip = $_SERVER['HTTP_FORWARDED_FOR'];
      } elseif (isset($_SERVER['HTTP_FORWARDED'])) {
        $ip = $_SERVER['HTTP_FORWARDED'];
      } else {
        $ip = $_SERVER['REMOTE_ADDR'];
      }
    }
    if (trim($ip) == '') {
      if (getenv('HTTP_X_FORWARDED_FOR')) {
        $ip = getenv('HTTP_X_FORWARDED_FOR');
      } elseif (getenv('HTTP_CLIENT_IP')) {
        $ip = getenv('HTTP_CLIENT_IP');
      } else {
        $ip = getenv('REMOTE_ADDR');
      }
    }

    /**
     * sanitize for validity as an IPv4 or IPv6 address
     */
    $ip = filter_var((string)$ip, FILTER_VALIDATE_IP);

    /**
     *  if it's not a valid IP address or still blank, set to a single dot
     */
    if ($ip === false || trim($ip) == '') $ip = '.';

    return $ip;
  }
Note also that your update 'lost' the check for $ip exactly equal to false, which is the filter_var return value and will result in a PHP Notice from trim since (bool)false is not a string.
If the default values are used, then yes the exact match to false is needed; however, in my final post after running a test and realizing that only three parameters were expected (eyes at one point thought saw four), I modified the default response to an empty quote which then wouldn't require the test for exactly false. If one or more of the additional filters were desired to be used, they could be added to the $options array as a 'filters' element. I did test in php 7.3 with strict mode to have the array in the filer_var call without issue, but the php manual implies that $options or some variable should be used rather than an array syntax.