Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 16th, 2004, 05:16 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default Detect country using php

We can get ip using $_SERVER['REMOTE_ADDR']
Can we know from which country request has arrivred?
I am curious!

__________________
`~@#\^%&*/\.<.\/-|+|_!:;..=?>
PHP, SEO | anshul shrivastava | mediasworks.org | FB
 
Old November 17th, 2004, 06:21 AM
Authorized User
 
Join Date: Oct 2004
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to SiliconFuRy
Default

http://sourceforge.net/projects/geoip/

Many shoes,

Jamez/SiliconFuRy
 
Old November 17th, 2004, 08:38 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

 
Quote:
Many shoes, Jamez
Then what

MaxMind GeoIP is a collection of APIs for looking up the location of an IP address. It includes support for lookup of country, region, city, latitude, and longitude. Free databases are available for the country.

Latest File Releases
.
.
This Project Has Not Released Any Files

I just asked if that is possible using few lines of PHP ! What are the fundamentals?
Quote:
quote:I am curious!
 
Old November 17th, 2004, 09:59 AM
Authorized User
 
Join Date: Oct 2004
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to SiliconFuRy
Default

;)
I don't think it is possible using PHP.
I'm not sure how much you know about TCP/IP but any person in the world can have any IP address (as long as its not reserved and not in use by someone else in the same subnet), so there is no way to say something like "person with IP 147.171.x.x definetly lives in the US", as any company in the world can reserve an IP subnet.

If you do want to do this urself, and don't fancy going with GeoIP, then one way is to reverse DNS the IP address, see if there's a recognisable domain suffix (.co.uk, .fr, .de etc) and map it to a country that way.

That way is pretty unreliable though, as a lot of ISPs will hand out hostnames to their users with a .com suffix, which could be anywhere in the world.

I think that the web stats software, "awstats" uses a method similiar to this, as it shows stats for people visiting from hostnames with a country identifier in their hostname, and just classes ".com" as "commercial".

Most reliable way i guess is for users to sign up to your site, and have "location/country" field as part of their profile. Of course, that won't show every single visitor :/

Many shoes ("Regards" for people wondering why I use 'shoes'),

Jamez/SiliconFuRy
 
Old November 29th, 2004, 07:11 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

I've c'in PHP forms that automatically select country from drop-down list box. This appears elegant to end-user and saves his/her work.

 
Old June 11th, 2008, 03:46 PM
Registered User
 
Join Date: Jun 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

$_SERVER['REMOTE_ADDR'] gets you the visitor's IP which you can then look up in a DB (some are offered for free). I found the following which gives a simple example using PHP & MySQL:
http://www.jameslittle.me.uk/detect-...with-php-mysql






Similar Threads
Thread Thread Starter Forum Replies Last Post
Can PHP detect include? paket Pro PHP 2 May 11th, 2008 06:49 AM
need help to create my country calendar dimension dbayona SQL Server 2000 1 July 4th, 2007 12:54 AM
selective validation Country/State dsmportal ASP.NET 2.0 Professional 3 August 9th, 2006 04:01 PM
selective validation Country/State dsmportal ASP.NET 1.0 and 1.1 Professional 0 August 3rd, 2006 12:35 PM
Find Country from IP? ccc_storage Classic ASP Professional 3 June 5th, 2005 10:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.