= 0; $index--) { $candidate = $chain[$index]; if ($candidate === '' || filter_var($candidate, FILTER_VALIDATE_IP) === false) { continue; } if (!isset($trusted[$candidate])) { return $candidate; } } return $remoteAddr; }