• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

Determining user IP address and using it

Hi All,
I wonder is it possible to determine the user's IP address and use it to make the default value for a drop-down menu approiate to it. For example, if the users IP address indicates that the user is from greater London, then have the "Greater London" appear as the default value in the drop-down menu. Is this a very complicated procedure??
3 Solutions
Determining the IP address is easy, it's in $_SERVER['REMOTE_ADDR'] (in most cases, if it's not a proxied request, etc.).

Matching it to a geographic location is a trickier task that you can do but any service that will be good at it is not going to be free. http://geobytes.com/IpLocator.htm?GetLocation is a good one, for example, and there are other services like that - their quality will really depend on the region where you are in - some are better in some countries, others in others.
Hi there

download the ip 2 country database from here

you can then read on how to import it to mysql here

That website is full of info on how to use it :D
btw it's free =)
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Also you can use that csv with this code


instead of doing a mysql database
It is possible to identify the geographic location of a user by country, but it is probably close to impossible to determine the actual area of that user within the country. For example, if I have a dynamic IP address from a national ISP, that could be assigned to me one day and then, the next day, be assigned to someone hundreds of miles away. Unfortunately I don't think it's possible.

The IP-to-country database is a good system for locating a user by country, but don't rely on it and do allow a user to change their country if they wish as it can't be guaranteed correct. Using a MySQL database and PHP script to determine this should be relatively easy. :-)
dereksheahanAuthor Commented:
Thanks guys,
Yeah I wanted it to change as for where the user was in Ireland. I.e. for each county have it change dynamically. Thats okay, think I'll leave it out of the project and might consider doing it somewhere down the line.
Hi Derek,
Thanks for the points :-)

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now