Skip to content

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.

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments