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开发者_StackOverflow中文版 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?
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
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.)
It works best for me http://www.ipinfodb.com/ip_location_api.php
精彩评论