Full Stack LAMP - MEAN Developer, Python developer. Certified Azure Developer. Freelance programmer/consultant/trainer.

Check if an IP address is private with PHP?

This snippet will detect a private IP address using PHP’s built in filter library and It will return false if the IP address is private.


FILTER_FLAG_IPV4 : Allows the IP address to be in IPv4 format.

FILTER_FLAG_NO_PRIV_RANGE : Fails validation for the following private IPv4 ranges:, and

Fails validation for the IPv6 addresses starting with FD or FC.

FILTER_FLAG_NO_RES_RANGE : Fails validation for the following reserved IPv4 ranges:,, and This flag does not apply to IPv6 addresses.

Leave a Reply