简体   繁体   English

在PHP和MySQL中跟踪用户所在的国家

[英]Track user's country in PHP & MySQL

I'm creating a URL Shortening website. 我正在创建一个URL缩短网站。 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. 我想我应该使用类似于GeoIP for PHP的库来获取国家/地区,但是MySQL怎么可能。 My weakness is the design of the MySQL tables. 我的弱点是MySQL表的设计。 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. 使用数字格式表示将用于查询国家/地区的ip范围。

Also: How to store and search for an IP Address 另外: 如何存储和搜索IP地址

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. 我要做的是针对每个视图,我会选择正在查看ip,lat&long或您想用于跟踪的任何对象的人。 Perhaps have either id, ip, lat, long, url . 也许有id, ip, lat, long, url The id could be autoincremented, and the ip, latitude, and longitude might combine to give you accurate results. ID可以自动增加,而ip,纬度和经度可以结合起来以提供准确的结果。 Just select the rows from the table where the URL is equal to the one wanted, and you're set. 只需从表中选择URL与想要的URL相等的行,即可进行设置。 (You could also have a 'user' column, if you want to show stats for all of the user's links.) (如果要显示所有用户链接的统计信息,则也可以有一个“用户”列。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM