Francesc
Francesc

Reputation: 1349

Track user's country in PHP & MySQL

I'm creating a URL Shortening website. I want to allow users to view the stats for the links. I planned to do Country stats. I think I should use a library similar to GeoIP for PHP to get the country, but, how can be the MySQL. My weakness is the design of the MySQL tables. Can you recommend me a table format, please?

Upvotes: 1

Views: 1017

Answers (3)

jack
jack

Reputation: 1435

It works best for me http://www.ipinfodb.com/ip_location_api.php

Upvotes: 0

Arianna
Arianna

Reputation: 11

What I would do is for each view, I would take the person who is viewing's ip, lat&long, or whatever you want to use for tracking. Perhaps have either id, ip, lat, long, url. The id could be autoincremented, and the ip, latitude, and longitude might combine to give you accurate results. Just select the rows from the table where the URL is equal to the one wanted, and you're set. (You could also have a 'user' column, if you want to show stats for all of the user's links.)

Upvotes: 0

zaf
zaf

Reputation: 23244

A table, something like:

id, fromip, toip, country

Use the number format for the ip ranges which you'll use to query for the country.

Also: How to store and search for an IP Address

Upvotes: 1

Related Questions