Need help to get ip of diffrent countries...
please help..
Need help to get ip of diffrent countries...
please help..
You need to provide more information to help us answer your question
What exactly are you trying to do? Take a user's IP address and determine what county it is from in a php script, or just a website to do it. OR do you just want to find the county's IP range? Please be more specific.
-Ben -- THE DYNAMIC DRIVERS
My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
I told my client to press F5, the client pressed F, then 5, *facepalm*
victory.jeet (02-21-2010)
I want the ip address script that can find the ip of diffrent countries like england and Ireland.
My requirement is that i want to show specific module not other then England and Ireland.
I found this freeware script online:
Put this in your functions page (or on the top of your page):
And this on your page you want to use it:PHP Code:<?php
function locateIp($ip){
$d = file_get_contents("http://www.ipinfodb.com/ip_query.php?ip=$ip&output=xml&timezone=false");
//Use backup server if cannot make a connection
if (!$d){
$backup = file_get_contents("http://backup.ipinfodb.com/ip_query.php?ip=$ip&output=xml&timezone=false");
$answer = new SimpleXMLElement($backup);
if (!$backup) return false; // Failed to open connection
}else{
$answer = new SimpleXMLElement($d);
}
$country_code = $answer->CountryCode;
$country_name = $answer->CountryName;
$region_name = $answer->RegionName;
$city = $answer->City;
$zippostalcode = $answer->ZipPostalCode;
$latitude = $answer->Latitude;
$longitude = $answer->Longitude;
//Return the data as an array
return array('ip' => $ip, 'country_code' => $country_code, 'country_name' => $country_name, 'region_name' => $region_name, 'city' => $city, 'zippostalcode' => $zippostalcode, 'latitude' => $latitude, 'longitude' => $longitude);
}
?>
Here is an example I made based on the API:PHP Code:<?
$ip = "74.125.45.100";
$ip_data = locateIp($ip);
echo "IP : " . $ip_data['ip'] . "\n";
echo "Country code : " . $ip_data['country_code'] . "\n";
echo "Country name : " . $ip_data['country_name'] . "\n";
echo "Region name : " . $ip_data['region_name'] . "\n";
echo "City : " . $ip_data['city'] . "\n";
echo "Zip/postal code : " . $ip_data['zippostalcode'] . "\n";
echo "Latitude : " . $ip_data['latitude'] . "\n";
echo "Longitude : " . $ip_data['longitude'] . "\n";
?>
You don't need to download anything else BTW unless you want to host the API on your site, you can go HEREPHP Code:<?
$ip=$_SERVER['REMOTE_ADDR'];
$ip_data = locateIp($ip);
echo "The IP " . $ip_data['ip'];
if($ip_data['country_name']=="England") echo " is from England";
elseif($ip_data['country_name']=="Ireland") echo " is from Ireland";
?>
-Ben -- THE DYNAMIC DRIVERS
My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
I told my client to press F5, the client pressed F, then 5, *facepalm*
victory.jeet (02-21-2010)
http://www.maxmind.com/app/ip-location
The above may work, but another option is maxmind GeoIP. I've used it and it works well. They have a free version and a paid version which is a little more accurate.
They have example scripts in various languages (including PHP).
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
You can also check out IP2Location.com which has the data as well as a web service that you can use to find the country from the IP address.
FraudLabs.com also has a free web service that you can utilize after signing up for a free account.
Bookmarks