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: 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16.
Fails validation for the IPv6 addresses starting with FD or FC.
FILTER_FLAG_NO_RES_RANGE : Fails validation for the following reserved IPv4 ranges: 0.0.0.0/8, 169.254.0.0/16, 192.0.2.0/24 and 18.104.22.168/4. This flag does not apply to IPv6 addresses.