Search code examples
phpgeolocation

IP range for Europe? Detect with PHP?


I am looking to implement the "Cookie Law" using PHP and JavaScript. I think it is pointless to have users from other continents fill out the form when they open up my site but it is unfortunately required for EU.

I tried searching for IP range for europe and I came up with nothing.

I know I can use explode() and $_SERVER['remote_addr'] and substr() to isolate the specific IP range the problem I am facing is what IPs to blacklist i.e. 194.XXX.XXX.XXX - 198.XXX.XXX.XXX?

Also, what would be the best way to implement this, would using if else statements work? I mean if the user is in europe, display some JS and if the user is in another display some other JS.

Thanks in advance!


Solution

  • You could use a GeoLocation Database to check for the Country using the REMOTE_ADDR in PHP.

    There is for example GeoLite which offers a PHP API Library