Reputation:
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!
Upvotes: 2
Views: 5699
Reputation: 2850
$ip = $_SERVER['REMOTE_ADDR'];
$country = file_get_contents("http://api.wipmania.com/".$ip."?[YOUR SITE URL]");
$eu_countries = array("BE", "BG", "CZ", "DK", "DE", "EE", "IE", "EL", "ES", "FR", "HR", "IT", "CY", "LV", "LT", "LU", "HU", "MT", "NL", "AT", "PL", "PT", "RO", "SI", "SK", "FI", "SE");
$checked = in_array(strtoupper($country), $eu_countries);
Upvotes: 0
Reputation: 585
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
Upvotes: 5