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.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments