• Resolved ryanbriscall

    (@ryanbriscall)


    The $ip parameter is modified then reused in the loop of ips/ranges, thereby cause any subsequent iteration to fail on checking $ip.

    I had to hack and change those instances of $ip to be renamed as $needle.

    public function ip_in_range( $ip, $list )
    {
    	foreach ( $list as $range )
    	{
    		$range = array_map('trim', explode('-', $range) );
    		if ( count( $range ) == 1 )
    		{
    			if ( (string)$ip === (string)$range[0] )
    				return true;
    		}
    		else
    		{
    			$low = ip2long( $range[0] );
    			$high = ip2long( $range[1] );
    			$needle = ip2long( $ip );
    			
    			if ( $low === false || $high === false || $needle === false )
    				continue;
    			
    			$low = (float)sprintf("%u",$low);
    			$high = (float)sprintf("%u",$high);
    			$needle = (float)sprintf("%u",$needle);
    			
    			if ( $needle >= $low && $needle <= $high )
    				return true;
    		}
    	}
    	
    	return false;
    }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘ip_in_range() loop $ip overrides itself causing invalid results.’ is closed to new replies.