Get country location of an IP with native PHP

Posted by Mint on Stack Overflow See other posts from Stack Overflow or by Mint
Published on 2010-03-18T07:46:23Z Indexed on 2010/03/18 7:51 UTC
Read the original article Hit count: 302

Filed under:
|
|
|

Read on before you say this is a duplicate, it's not. (as far as I could see)

I want to get the county code in php from the client.

Yes I know you can do this using external sites or with the likes of "geoip_record_by_name" but I don't want to be dependent on an external site, and I can't install "pear" for php as im using shard Dreamhost hosting.

I thought I could just do something like this:

$output = shell_exec('whois '.$ip.' -H | grep country | awk \'{print $2}\'');
echo "<pre>$output</pre>";

But dreamhost seems to have an old version of whois (4.7.5), so I get this error on allot of IPs:

Unknown AS number or IP network. Please upgrade this program.

So unless someone knows how to get a binary of a newer version of whois onto dreamhost im stuck.

Or is there another way I could get the country code from the client who is loading the page?

© Stack Overflow or respective owner

Related posts about php5

Related posts about dreamhost