Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

find user location based on IP address or host address 1

Status
Not open for further replies.

neisye

Programmer
Mar 5, 2008
11
AU
hi,
How do you find user location based on IP address or host address. in php.

thanks,
arden
 
Get hold of a data source that has IP/Geo data. I don't think you can work it out from the numbers alone.

--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
Use this
Code:
$IP = $_SERVER['REMOTE_ADDR'];
$SSID = htmlentities(SID);
// If IP address exists
// Get country (and City) via  api.hostip.info
if (!empty($IP)) {
  $country=file_get_contents('[URL unfurl="true"]http://api.hostip.info/get_html.php?ip='.$IP);[/URL]

// Reformat the data returned (Keep only country and country abbr.
list ($_country) = explode ("\n", $country);
$_country = str_replace("Country: ", "", $_country);
}

Good luck!
 
I also forgot to mention that this is totally dependent on the target URL being up and running.

You may experience slow performance while making the inquiry.

Hope all goes well!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top