且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从IP地址确定邮政编码和城市?

更新时间:2023-02-26 09:24:55

我使用的是ip2nation: http://www.ip2nation.com



这是一个完全免费的国家映射IP数据库。他们在他们的网站上包含了一些PHP示例脚本。



我在我的WordPress博客上使用它以及Ozh的免费 IP to Nation WordPress插件

即使你不是使用WordPress,下载插件,因为它会给你一个很好的PHP代码访问数据库。他甚至还有一个很好的小国家国旗,你可以在旁边显示,或者不用国家名称,这就是我自己显示标志的位置,可以在博客的评论者名字旁边显示。

真的,你不需要这个API。所有你需要的是数据库和能够编写PHP和SQL代码来访问它。



我不推荐ip2location用于临时使用。他们为他们的数据库收取很多费用,他们的数据库非常大,并且比大多数人需要更多的细节。



但ip2nation只能进入***别。如果您确实需要Cities和Zipcodes(尽管事实上它们可能是错误的,但其他答案/评论已经声明),那么除了ip2location之外,你可以试试GeoBytes 。它们具有特别适用于特定于地理位置的网站内容的组件,如GeoSelect: http://www.geobytes。 com / GeoSelect.htm



另外在Google上搜索ip to zipcode

I am looking for advice for open API or 3d party products which will help to convert an IP address to a zip code and city, to make geo-specific web site content.

What I use is ip2nation: http://www.ip2nation.com

It is a completely free MySQL database of IP to country mappings. They include a few sample PHP scripts at their site.

I use it on my WordPress blog along with Ozh's free IP to Nation WordPress Plugin

Even if you are not using WordPress, download the plugin as it will give you a good set of PHP code to access the database with. He even has a nice set of tiny country flags that you can display next to, or instead of the country name, which is what I do to automatically show flags next my blog's commenter's names.

Really, you don't need an API for this. All you need is the database and an ability to write the PHP and SQL code to access it.

I wouldn't recommend ip2location for casual use. They charge a lot for their databases, and their databases are very large, and have more detail than most people need.

But ip2nation only goes to the Country level. If you do need Cities and Zipcodes (despite the fact that they can be wrong as other answers/comments have stated), then in addition to ip2location, you can try GeoBytes. They have components specifically suited for geo-specific web site content, such as GeoSelect: http://www.geobytes.com/GeoSelect.htm

Also search for "ip to zipcode" on Google.