Skip to main content

Posts

Showing posts from October, 2010

Finding Geographical location from IP address

How to find the country from IP Address?

After a long search i could find a solution for that.

First function is for fetching contents from an API url
the API Url used here is http://api.hostip.info/?ip=Your IP Address

This function will work if your server allows thi stype of fetching from another server



functiongetCountryCityFromIP($ipAddr)
{
//function to find country and city from IP address
//Developed by Roshan Bhattarai http://roshanbh.com.np
//verify the IP address


ip2long($ipAddr)== -1 || ip2long($ipAddr) === false ? trigger_error("Invalid IP", E_USER_ERROR) : "";


        $ipDetail=array(); //initialize a blank array
//get the XML result from hostip.info
        $xml = file_get_contents("http://api.hostip.info/?ip=".$ipAddr);



    //get the city name inside the node and
                preg_match("@(\s)*(.*?)@si",$xml,$match);
//assing the city name to the array
                $ipDetail['city']=$match[2];
//get the country name ins…


Urgent Openings for PHP trainees, Andriod / IOS developers and PHP developers in Kochi Trivandrum Calicut and Bangalore. Please Send Your updated resumes to recruit.vo@gmail.com   Read more »
Member
Search This Blog