I want to collect basic user information when they land on an index page, such as:

IP
Country
City
State
Zip Code

I've looked into sites such as ipinfo.io that offer a service regarding these details, but think it may be easier to collect the same info via PHP. From some sample PHP code I've looked at, it seems easy and possible.

My question is what would generally be a better option: PHP or using a service (the service limits the amount of hits processed per day, 10,000, so that is a consideration)?

I am just looking for advice on this at this point, the best options to consider, and possible issues regarding this before I attempt to implement this.

Thanks in advance!

You can use PHP to retrieve a user's IP address. And you can use the JavaScript-based HTML5 geo API to retrieve a user's latitude and longitude (coordinates), provided they agree to it.

However, you need a third party service or library or something to actually determine a user's city, state, country, zip code, area code, etc.

I would recommend Geo2IP. That's what I've been using for years and there is a free version that lets you download their database and use it directly, albeit it's a little less accurate. However, what I like about it is that it doesn't depend on any third party API calls, so once you download it you can use it locally without limitation.

Thanks for your help, Dani.

Member Avatar for diafol

If that's the same one as I used a few years ago, be aware the file is ginormous (as you may expect).

Sorry, I wrote Geo2IP and it's actually GeoIP2. And it converts the IPs you have to geos. See, I was almost right.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.