How do u tell what country a client is browsing from ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

How do u tell what country a client is browsing from ?

Post by lazy_yogi »

Anyone know how to tell what country a client is from ?
If I use "gethostbyname" I can get the users IP address.
Any idea how to find what country this is, either from that function or any other ?

Cheers
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Demo: http://perfectphp.com/ipatlas/plot.php
Source: http://www.xpenguin.com/ip-atlas.php
Download: http://www.xpenguin.com/ip-atlas-1.0.zip

You can either put in a domain (http://www.aol.com) or it's ip (64.12.187.24) [any ip for that matter]
Image Image
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

That's pretty neat. But it's off by far for me. It says i'm in my nation's capital when infact i'm on the other side of the country.
You at (142.xxx.xx.xx) are located in Ottawa, Ontario (province), Canada. (45.42, -75.72)
But it's a very nice program.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

and I am in Amsterdam but obviously too stoned to notice ;)
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

Post by lazy_yogi »

OMG ! That was by far the worst code I've ever seen in my life !!

Here's some snippets from there :

Code: Select all

function stuffanalyze($stuff) {

for ($count = 0; $count < count($stuff2); $count++) {
  $stuff2[$count] = $stuff2[$count][0];
  $stuff2[$count] = ucwords(strtolower(trim(substr(substr($stuff2[$count], 15), 0, -5))));
}

}



function getstuff($address, $local) {
 .....
}
I couldn't read that <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>
Anyone have any other ideas how to look up a country from an IP ?

Cheers
User avatar
bender
Forum Newbie
Posts: 11
Joined: Sun Jan 12, 2003 6:53 am
Location: Sydney Australia

Post by bender »

...last time I checked Sydney was located in Australia - not the Netherlands ?!?!?!
Rob the R
Forum Contributor
Posts: 128
Joined: Wed Nov 06, 2002 2:25 pm
Location: Houston

Post by Rob the R »

Could you use the value in the $_SERVER["HTTP_ACCEPT_LANGUAGE"] variable? This often has the country abbreviation in the value. Of course, this is entirely user-configurable (which means the user can set it to whatever they want) and is meant to identify the language and not necessarily the country.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Check this class here:
http://www.phpclasses.org/browse.html/package/693.html

It's not working perfectly, but it's a very nice example.
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

Post by lazy_yogi »

Thanx Rob, that seems to be what I'm looking for

Cheers
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

http://www.xpenguin.com/ip-atlas.php wrote: IP-Atlas 1.0 (Released July 3rd)

IP-Atlas tries to plot your location or any other host on the internet using the NetGeo data. It finds the latitude and longitude coordinates of the host and plots it on an image for you. You can try the demo and/or download it (91k). IP-Atlas requires PHP and optionally the GD library.
Post Reply