PHP IF Statment Based On Geo Location? - php

Is there a way to do a PHP If statement based on the persons location?
My problem comes down to Amazon Affiliate links. The link to buy a DVD on Amazon.co.uk is different to the one to buy from Amazon.com and I want a way to only show the correct one.
At the same time, If they aren't based in either country, then I don't want the link to show in the first place.
Example:
If Location = UK; print "amazon-UK-link"
If Location = US; print "amazon-US-link"
If location = None of the above; print nothing

You can use: string geoip_country_code_by_name ( string $hostname )
Example:
<?php
$country = geoip_country_code_by_name('www.example.com');
if ($country) {
echo 'This host is located in: ' . $country;
}
?>
Output:
This host is located in: US
For your case you can use: geoip_country_code_by_name($_SERVER['REMOTE_ADDR']); to get the country code for the current user.

You're going to have to use the visitor's IP address to lookup their physical location. Apart from using the GeoIP extension for PHP (as stewe pointed out), there are two ways of doing this:
The easy way
Use an external service like http://www.hostip.info
With your own MySQL data
1.) Retrieve the visitors' IP address:
if (getenv('HTTP_X_FORWARDED_FOR'))
{
$ip_address = getenv('HTTP_X_FORWARDED_FOR');
}
else
{
$ip_address = getenv('REMOTE_ADDR');
}
2.) Convert the visitor's IP address to an IP Number:
$ips = explode(".",$ip_address);
return ($ips[3] + $ips[2] * 256 + $ips[1] * 256 * 256 + $ips[0] * 256 * 256 * 256);
3.) Locate the IP Number from your database which you can download here.
For example: the IP Address 202.186.13.4 converts to IP Number 3401190660. It is between the beginning and the ending of the following IP numbers:
Beginning_IP | End_IP | Country | ISO
-------------+-------------+----------+----
3401056256 | 3401400319 | MALAYSIA | MY

You need to use geoip for that by maxmind http://www.maxmind.com/app/ip-location or there's another option, search for an IP to Country API, there some on the web.

You can use a simple API from http://www.geoplugin.net/
$xml = simplexml_load_file("http://www.geoplugin.net/xml.gp?ip=".getRealIpAddr());
echo $xml->geoplugin_countryName ;
echo "<pre>" ;
foreach ($xml as $key => $value)
{
echo $key , "= " , $value , " \n" ;
}
function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
Output
United States
geoplugin_city= San Antonio
geoplugin_region= TX
geoplugin_areaCode= 210
geoplugin_dmaCode= 641
geoplugin_countryCode= US
geoplugin_countryName= United States
geoplugin_continentCode= NA
geoplugin_latitude= 29.488899230957
geoplugin_longitude= -98.398696899414
geoplugin_regionCode= TX
geoplugin_regionName= Texas
geoplugin_currencyCode= USD
geoplugin_currencySymbol= $
geoplugin_currencyConverter= 1
It makes you have so many options you can play around with
Thanks
:)

Related

How to block certain Ip ranges via ip2long in php

Lets assume I have the following IP ranges that I want to block
89.96.53.158 and 89.96.53.189
This how am trying to implement it.
My questions: is it the best way to do it as per code below. Is the coding below right for it
$ip = sprintf('%u', ip2long($_SERVER['REMOTE_ADDR']));
$start_ip = sprintf('%u', ip2long("89.96.53.158"));
$end_ip = sprintf('%u', ip2long("89.96.53.189"));
// stop only ip range between 89.96.53.158 - 89.96.53.189
if ($ip >= $start_ip && $ip <= $end_ip) {
echo "you cannot access our site";
exit();
}
can I also achieve that using strpos() functions
Yes I figured out another way to do it with strpos() method
if(strpos($_SERVER['REMOTE_ADDR'], "89.96") === 0)
{
echo "you cannot access our site";
exit();
}
If you notice, the === operator makes sure that the 89.96 is at the beginning of the IP address.
This means that you can specify as much of the IP address as you want, and it will block no matter what numbers come after it.

How to detect whether a URL is local area network(LAN) url by PHP? [duplicate]

I need to check if a file is opened "locally" (same machine or network). I'm using:
<?php
if ((substr($_SERVER['REMOTE_ADDR'],0,8) == "192.168.") || ($_SERVER['REMOTE_ADDR'] == "127.0.0.1")) {
// client is local
} else {
// client is not local
}
But I'm not sure this is the best way.
What is a more foolproof way of doing this?
What Friek said is true, but provided that you know how to get the real client's IP, you can tell if it's a local address using PHP filters:
if ( ! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) )
{
// is a local ip address
}
"Foolproof," as always, can be tricky.
If we do restrict ourselves to IPv4, then checking for "127.0.0.1" takes care of the localhost case, but checking against "192.168." is plain wrong - it will only work if the script is being run on a server which happens to be on the 192.168 network, using a 16-bit subnet mask.
Checking $_SERVER['REMOTE_ADDR'] against $_SERVER['SERVER_ADDR'] would be a better bet. This still doesn't take care of the case of a multi-homed host (ie one which has several IP addresses in addition to 127.0.0.1), though.
In order to catch all same-network cases, you'd need to check the combination of SERVER_ADDR and subnet mask against REMOTE_ADDR, but the subnet mask isn't available in $_SERVER.
BUT I found a function which does pretty much what you want here. It's a couple of screens down and it's called clientInSameSubnet. Not my code, but looks right.
In case anyone has trouble finding the above code, suggested by #Uffe, I've included it below:
<?php
/**
* Check if a client IP is in our Server subnet
*
* #param string $client_ip
* #param string $server_ip
* #return boolean
*/
function clientInSameSubnet($client_ip=false,$server_ip=false) {
if (!$client_ip)
$client_ip = $_SERVER['REMOTE_ADDR'];
if (!$server_ip)
$server_ip = $_SERVER['SERVER_ADDR'];
// Extract broadcast and netmask from ifconfig
if (!($p = popen("ifconfig","r"))) return false;
$out = "";
while(!feof($p))
$out .= fread($p,1024);
fclose($p);
// This is to avoid wrapping.
$match = "/^.*".$server_ip;
$match .= ".*Bcast:(\d{1,3}\.\d{1,3}i\.\d{1,3}\.\d{1,3}).*";
$match .= "Mask:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/im";
if (!preg_match($match,$out,$regs))
return false;
$bcast = ip2long($regs[1]);
$smask = ip2long($regs[2]);
$ipadr = ip2long($client_ip);
$nmask = $bcast & $smask;
return (($ipadr & $smask) == ($nmask & $smask));
}

PhP - How do I block every EU country except the UK, and allow all non EU countries?

I want a page to block EU countries except the UK, while allowing all other non-EU countries. By block I mean I want another message, such as "Service Unavailable in your Country" appearing rather than the normal page content. How can this be done?
Note: I do not want to effect google-bot ranking by blocking these non-UK EU countries.
Edit: It's a VAT MOSS thing, nothing sinister.
You can use the geoplugin.net geo API.
//Get user IP address
$ip=$_SERVER['REMOTE_ADDR'];
//Using the API to get information about this IP
$details = json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=$ip"));
//Using the geoplugin to get the continent for this IP
$continent=$details->geoplugin_continentCode;
//And for the country
$country=$details->geoplugin_countryCode;
//If continent is Europe
if($continent==="EU" && $country==="UK" || $continent!="EU"){
//Do action if country is UK or not from Europe
}else{
//Do action if country is in Europe , but its not UK
}
Edited the code a bit :)
You'll need to check IP ranges and block those that are in the ranges you don't want. Note that it's possible to get around these restrictions using a proxy or VPN or some such technology.
As Frank says, you will need to check the IP addresses against a geolocation database. An answered question on this topic already exists.
Below is a re-usable PHP function that uses 'ip-api.com' API to return location data on an IP and check it against a white-list of current EU member countries. The white-list is easy to maintain, which is good, as countries entering and leaving the EU are in a continual flux. The white-list was put together on July 24, 1018 with the data crossed-checked between the EU official website and Wikipedia. The 'ip-api.com' API is free for personal use (contact for commercial use), and can be run from your local server as well, and without registration or domain requirement.
function inEU($ip_input){
// Validate the IP address
if (filter_var($ip_input, FILTER_VALIDATE_IP) === false){
// Not a valid IP address - build error response
$message_string =
'<div style="width:100%; margin-top:50px; text-align:center;">'.
'<div style="width:100%; font-family:arial,sans-serif; font-size:24px; color:#c00; centered">'.
'ERROR: <span style="color:#fd0">Invalid IP Address</span>'.
'</div>'.
'</div>';
echo $message_string;
exit;
}
// Array of country names and country codes of European Union member countries
$eu_members = array(
'Austria','AT', 'Belgium','BE', 'Bulgaria','BG',
'Croatia','HR', 'Cyprus','CY', 'Czech Republic','CZ',
'Denmark','DK', 'Estonia','EE', 'Finland','FI',
'France','FR', 'Germany','DE', 'Greece','GR',
'Hungary','HU', 'Ireland','IE', 'Italy','IT',
'Latvia','LV', 'Lithuania','LT', 'Luxembourg','LU',
'Malta','MT', 'Netherlands','NL', 'Netherlands Antilles','AN',
'Poland','PL', 'Portugal','PT', 'Romania','RO',
'Slovakia','SK', 'Slovenia','SI', 'Spain','ES',
'Sweden','SE', 'United Kingdom','GB','UK'
);
$query_url = 'http://ip-api.com/json/'.$ip_input; // Build query URL for IP to JSON Data request
$ip_data_fetched = file_get_contents($query_url); // Return IP Data JSON as a string
$ip_data_fetched = utf8_encode($ip_data_fetched); // Encode returned JSON string to utf-8 if needed
$ip_data = json_decode($ip_data_fetched); // Decode utf-8 JSON string as PHP object
// Get the Country and Country Code for the IP from the returned data
$country = $ip_data->country; // Country Name (i.e; 'United States')
$countryCode = $ip_data->countryCode; // Country Code (i.e; 'US')
// Check the EU members array for match to either country or country code
$in_EU = false; // Ref for function boolean value returned - set false
$num_members = count($eu_members); // Number of indexes in EU members array (not # of members)
for ($i = 0; $i < $num_members; $i++){
$lc_eu_members = strtolower($eu_members[$i]);
if ($lc_eu_members === strtolower($country) || $lc_eu_members === strtolower($countryCode)){
$in_EU = true;
break;
}
}
return $in_EU;
}
And to use the function...
if (inEU( $ip )){
// IP address IS in an EU country
}
else {
// IP address IS NOT in an EU country
}
This function also cross-checks the returned location data in the same loop, so if there is a typo in one var, it would still find the location using the other var. For both to be wrong is not likely.
Unlike the 'geoplugin.net' API in Quadcore's example, which only checks on a continent value of 'EU', this function checks it against actual EU member countries.
This function can also be easily be adapted to work with many other IP to location API's that return a JSON response, including the 'geoplugin.net' API in Quadcore's example. It can easily be adapted as an 'allow only' white-list, rather than 'ban' white-list.
Hope this helps!

Google Maps API with PHP to find distance between two locations

On my current project, which is a delivery system, I have a list of available delivery drivers, which is shown on an orders page. But what I need is to show the distance each delivery is from the customers address. The distance should be shown next to each driver's name. Anyone have any clues on how I would go about this?
Assuming that you want driving distance and not straight line distance, you can use the Directions web service:
You need to make an http or https request from your PHP script and the parse the JSON or XML response.
Documentation:
https://developers.google.com/maps/documentation/directions/
For example:
Boston,MA to Concord,MA via Charlestown,MA and Lexington,MA (JSON)
http://maps.googleapis.com/maps/api/directions/json?origin=Boston,MA&destination=Concord,MA&waypoints=Charlestown,MA|Lexington,MA&sensor=false
Boston,MA to Concord,MA via Charlestown,MA and Lexington,MA (XML)
http://maps.googleapis.com/maps/api/directions/xml?origin=Boston,MA&destination=Concord,MA&waypoints=Charlestown,MA|Lexington,MA&sensor=false
Note that there are usage limits.
You can easily calculates the distance between two address using Google Maps API and PHP.
$addressFrom = 'Insert from address';
$addressTo = 'Insert to address';
$distance = getDistance($addressFrom, $addressTo, "K");
echo $distance;
You can get the getDistance() function codes from here - http://www.codexworld.com/distance-between-two-addresses-google-maps-api-php/
this will out seconds between 2 location
$origin =urlencode('Optus Sydney International Airport, Airport Drive, Mascot NSW 2020, Australia');
$destination = urlencode('Sydney NSW, Australia');
$url = "https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=$origin&destinations=$destination&key=your_key";
$data = #file_get_contents($url);
$data = json_decode($data,true);
echo $data['rows'][0]['elements'][0]['duration']['value'];

Is it possible to check whether an IP address comes from a specific country without using GeoIP?

So I want to check if the user is in specific county
$ip = user ip;
$countryIP = some number;
if($ip == $countryIP){echo 'okey';} else {echo 'not okey';}
I dont want to use database with geo location since I need it for only one country.Also i dont want to use third party services.
For example abc.go.com/watch is only for US and I want to do something similar to that
Thanks :)
There is no way to find out if an ip address is assigned to a given country without performing GeoIP on it.
Ok, provided you're happy with checking Bulgaria against the block you indicated, then you can do it reasonably simply - all you need to do is convert the ip addresses to the numerical notation.
77.85.0.0/16 means any code from 77.85.0.0 to 77.85.255.255 - now convert these to a numerical values:
77*256^3+85*256^2+0*256+0 = 1297416192
77*256^3+85*256^2+255*256+255 = 1297481727
Now convert the IP you want to check in the same manner - and verify that it's between these two numbers. Of course, it's not as simple as you are saying. There are over 400 different blocks for Bulgaria. If you care about it all, here's the full list of their numerical representation (as of the last update). Check yourself, for example, here: http://www.countryipblocks.net/country-blocks/select-formats/
# Country: BULGARIA
# ISO Code: BG
# Total Networks: 497
# Total Subnets: 4,148,224
31.13.192.0/18
31.41.16.0/21
31.211.128.0/19
37.60.136.0/21
37.63.0.0/17
37.130.240.0/21
37.157.136.0/21
37.157.160.0/19
46.10.0.0/16
46.16.192.0/21
46.35.160.0/19
46.40.64.0/18
46.47.64.0/18
46.55.128.0/17
46.229.192.0/20
46.232.152.0/21
46.233.0.0/18
46.237.64.0/18
46.238.0.0/18
46.249.64.0/19
46.252.48.0/20
46.253.0.0/20
46.254.128.0/21
62.44.96.0/19
62.73.64.0/18
62.176.64.0/19
62.176.96.0/19
62.182.112.0/21
62.204.128.0/19
62.213.160.0/19
62.221.128.0/19
77.70.0.0/17
77.71.0.0/17
77.76.0.0/18
77.76.128.0/18
77.77.0.0/18
77.77.128.0/18
77.78.0.0/18
77.78.128.0/18
77.85.0.0/16
77.95.232.0/21
77.236.160.0/19
77.238.64.0/19
77.246.208.0/20
78.40.136.0/21
78.83.0.0/16
78.90.0.0/16
78.108.240.0/20
78.128.0.0/17
78.130.128.0/17
78.142.0.0/18
78.154.0.0/19
78.159.128.0/19
79.100.0.0/16
79.110.112.0/20
79.124.0.0/18
79.124.64.0/19
79.132.0.0/19
79.134.32.0/19
79.134.160.0/19
80.72.64.0/20
80.72.80.0/20
80.78.224.0/20
80.80.128.0/20
80.80.144.0/20
80.95.16.0/20
80.253.48.0/20
81.161.240.0/20
82.101.64.0/18
82.103.64.0/18
82.118.224.0/19
82.119.64.0/19
82.137.64.0/18
82.146.0.0/19
82.147.128.0/19
82.199.192.0/19
83.97.24.0/21
83.97.64.0/21
83.142.16.0/21
83.143.144.0/21
83.143.176.0/21
83.143.248.0/21
83.148.64.0/18
83.222.160.0/19
83.228.0.0/17
84.21.192.0/19
84.22.0.0/19
84.38.240.0/20
84.40.64.0/18
84.43.128.0/17
84.54.128.0/18
84.201.192.0/20
84.238.128.0/17
84.242.128.0/18
84.252.0.0/18
85.11.128.0/18
85.14.0.0/18
85.91.128.0/19
85.95.64.0/19
85.118.64.0/19
85.118.192.0/21
85.130.0.0/17
85.187.0.0/16
85.196.128.0/18
85.217.128.0/17
85.239.128.0/19
85.255.128.0/20
85.255.160.0/20
87.97.128.0/17
87.116.64.0/18
87.118.128.0/18
87.119.64.0/18
87.120.0.0/16
87.121.0.0/16
87.126.0.0/16
87.227.128.0/17
87.239.152.0/21
87.246.0.0/18
87.247.248.0/21
87.252.160.0/19
87.254.160.0/19
88.80.96.0/19
88.80.128.0/19
88.87.0.0/19
88.203.128.0/17
88.213.192.0/18
89.25.0.0/17
89.106.96.0/19
89.186.192.0/19
89.190.192.0/19
89.215.0.0/16
89.252.192.0/18
89.253.128.0/18
90.154.128.0/17
91.92.0.0/16
91.134.0.0/16
91.139.128.0/17
91.148.128.0/18
91.191.208.0/20
91.192.236.0/22
91.193.156.0/22
91.193.200.0/22
91.195.24.0/23
91.196.64.0/22
91.196.124.0/22
91.196.224.0/22
91.198.119.0/24
91.198.132.0/24
91.198.181.0/24
91.198.228.0/24
91.199.36.0/24
91.199.128.0/24
91.199.150.0/24
91.199.237.0/24
91.199.247.0/24
91.201.172.0/22
91.204.156.0/22
91.206.20.0/23
91.206.138.0/23
91.207.190.0/23
91.209.8.0/24
91.209.21.0/24
91.209.146.0/24
91.210.88.0/22
91.211.108.0/22
91.211.188.0/22
91.211.232.0/22
91.212.13.0/24
91.212.17.0/24
91.212.37.0/24
91.212.163.0/24
91.212.201.0/24
91.212.233.0/24
91.212.235.0/24
91.213.12.0/24
91.215.216.0/22
91.216.71.0/24
91.216.95.0/24
91.216.174.0/24
91.216.253.0/24
91.217.148.0/24
91.217.205.0/24
91.217.215.0/24
91.218.80.0/22
91.220.176.0/24
91.220.189.0/24
91.221.254.0/23
91.222.20.0/22
91.223.66.0/24
91.226.226.0/23
91.228.38.0/24
91.230.6.0/23
91.230.192.0/22
91.230.230.0/24
91.230.231.0/24
91.232.209.0/24
91.233.32.0/24
91.234.19.0/24
91.234.21.0/24
91.234.92.0/22
91.235.164.0/24
91.235.248.0/22
91.236.144.0/22
91.237.56.0/22
91.237.102.0/23
92.62.240.0/20
92.247.0.0/16
93.93.8.0/21
93.94.136.0/21
93.123.0.0/17
93.152.128.0/17
93.155.128.0/17
93.183.128.0/18
94.26.0.0/17
94.72.128.0/18
94.73.0.0/18
94.101.192.0/20
94.139.192.0/19
94.155.0.0/16
94.156.0.0/16
94.190.128.0/17
94.236.128.0/17
95.42.0.0/16
95.43.0.0/16
95.87.0.0/18
95.87.192.0/18
95.111.0.0/17
95.140.208.0/20
95.158.128.0/18
95.168.224.0/19
95.169.192.0/19
109.104.192.0/19
109.107.64.0/19
109.120.192.0/18
109.121.128.0/18
109.121.192.0/18
109.160.0.0/17
109.199.128.0/19
109.199.224.0/19
128.140.176.0/20
130.185.192.0/18
130.204.0.0/16
145.255.192.0/19
149.62.192.0/18
158.58.192.0/18
164.138.216.0/21
176.12.0.0/18
176.67.232.0/21
176.222.0.0/20
178.16.128.0/20
178.75.192.0/18
178.132.80.0/21
178.169.128.0/17
178.239.112.0/20
178.239.224.0/20
178.249.168.0/21
178.254.192.0/18
188.124.64.0/19
188.126.0.0/19
188.127.64.0/19
188.254.128.0/17
192.58.32.0/22
192.92.129.0/24
192.162.231.0/24
193.9.16.0/24
193.16.102.0/24
193.16.157.0/24
193.16.246.0/24
193.17.229.0/24
193.19.172.0/22
193.22.103.0/24
193.22.248.0/24
193.23.52.0/24
193.24.240.0/22
193.25.162.0/23
193.26.14.0/24
193.26.216.0/24
193.28.250.0/24
193.29.55.0/24
193.30.228.0/22
193.36.35.0/24
193.37.238.0/24
193.41.64.0/22
193.41.182.0/23
193.41.188.0/22
193.43.26.0/24
193.47.74.0/24
193.68.0.0/19
193.68.96.0/19
193.68.128.0/17
193.84.86.0/24
193.93.24.0/22
193.104.79.0/24
193.104.165.0/24
193.105.60.0/24
193.105.148.0/24
193.105.151.0/24
193.105.196.0/24
193.107.36.0/22
193.107.68.0/22
193.108.24.0/24
193.108.32.0/23
193.109.54.0/23
193.110.82.0/24
193.110.132.0/24
193.110.159.0/24
193.110.216.0/21
193.111.89.0/24
193.111.194.0/23
193.138.67.0/24
193.142.0.0/24
193.150.67.0/24
193.151.20.0/22
193.151.80.0/22
193.160.159.0/24
193.161.192.0/24
193.164.222.0/23
193.169.198.0/23
193.178.152.0/23
193.178.166.0/24
193.178.222.0/24
193.186.38.0/24
193.192.48.0/23
193.192.56.0/23
193.193.162.0/23
193.193.164.0/24
193.193.182.0/24
193.194.140.0/23
193.194.156.0/24
193.200.1.0/24
193.200.2.0/24
193.200.8.0/24
193.200.12.0/24
193.200.14.0/23
193.200.16.0/23
193.200.24.0/24
193.200.28.0/24
193.201.114.0/23
193.201.172.0/24
193.201.240.0/22
193.202.108.0/24
193.203.198.0/23
193.218.0.0/24
193.228.152.0/24
193.254.29.0/24
194.0.32.0/24
194.0.235.0/24
194.8.4.0/24
194.8.53.0/24
194.8.60.0/24
194.9.6.0/23
194.12.224.0/19
194.34.12.0/24
194.36.167.0/24
194.48.206.0/24
194.50.73.0/24
194.50.76.0/24
194.50.122.0/24
194.54.140.0/22
194.63.136.0/22
194.79.12.0/22
194.88.228.0/23
194.88.250.0/23
194.110.205.0/24
194.141.0.0/19
194.141.32.0/19
194.141.64.0/18
194.141.128.0/17
194.145.63.0/24
194.145.160.0/22
194.146.232.0/22
194.150.116.0/22
194.150.180.0/23
194.153.118.0/24
194.153.145.0/24
194.169.231.0/24
194.187.132.0/22
194.246.110.0/23
195.8.222.0/23
195.10.193.0/24
195.20.20.0/22
195.20.24.0/22
195.22.146.0/23
195.24.32.0/19
195.24.88.0/21
195.28.6.0/23
195.34.96.0/19
195.35.84.0/24
195.39.198.0/23
195.39.212.0/23
195.42.142.0/23
195.47.193.0/24
195.54.44.0/23
195.62.22.0/23
195.64.160.0/23
195.66.125.0/24
195.68.200.0/23
195.68.214.0/23
195.69.108.0/22
195.69.120.0/22
195.69.164.0/22
195.72.112.0/24
195.74.85.0/24
195.85.215.0/24
195.88.74.0/23
195.88.140.0/23
195.96.224.0/19
195.110.24.0/23
195.114.112.0/23
195.128.132.0/24
195.128.134.0/24
195.128.224.0/23
195.137.252.0/23
195.138.128.0/19
195.149.71.0/24
195.149.248.0/21
195.162.72.0/23
195.170.166.0/24
195.170.178.0/24
195.177.218.0/23
195.177.248.0/23
195.178.8.0/23
195.178.98.0/23
195.178.116.0/23
195.182.41.0/24
195.182.44.0/24
195.189.80.0/22
195.189.224.0/23
195.191.34.0/23
195.191.60.0/23
195.191.94.0/23
195.191.148.0/23
195.214.248.0/21
195.216.228.0/24
195.225.51.0/24
195.225.124.0/22
195.225.252.0/22
195.230.0.0/19
195.234.84.0/22
195.234.236.0/22
195.238.84.0/23
195.242.106.0/23
195.242.126.0/23
195.242.240.0/22
195.246.240.0/23
212.5.32.0/19
212.5.128.0/19
212.21.128.0/19
212.25.32.0/19
212.36.0.0/19
212.39.64.0/19
212.43.32.0/19
212.45.64.0/19
212.50.0.0/19
212.50.64.0/19
212.56.0.0/19
212.70.128.0/19
212.72.192.0/19
212.73.128.0/19
212.75.0.0/19
212.91.160.0/19
212.95.160.0/19
212.104.96.0/19
212.116.128.0/19
212.117.32.0/19
212.122.160.0/19
212.124.64.0/19
212.233.128.0/17
213.16.32.0/19
213.91.128.0/17
213.108.240.0/21
213.130.64.0/19
213.137.32.0/19
213.145.96.0/19
213.149.128.0/19
213.167.0.0/19
213.169.32.0/19
213.191.192.0/19
213.214.64.0/19
213.222.32.0/19
213.226.0.0/19
213.226.32.0/19
213.231.128.0/18
213.240.192.0/18
217.9.224.0/20
217.10.240.0/20
217.18.240.0/20
217.30.208.0/20
217.75.128.0/20
217.75.144.0/20
217.79.32.0/20
217.79.64.0/20
217.79.80.0/20
217.145.80.0/20
217.145.160.0/20
217.174.48.0/20
217.174.144.0/20
another way
$continent = geoip_continent_code_by_name('www.example.com');
if ($continent) {
echo 'This host is located in: ' . $continent;
}
http://www.php.net/manual/en/function.geoip-continent-code-by-name.php

Categories