How can I show different content to website visitors from a specific country in PHP?

狂风中的少年 提交于 2019-12-18 07:34:52

问题


On my Wordpress blog, I want to show additional content to people from Finland on all pages. Very much like the Feedback button at the left edge of the screen on printfriendly.com. How can I achieve this most reliably using PHP?


回答1:


My suggestion would be to use the PHP GeoIP functions to determine the users location based on IP, and serve appropriate content based on that.

More information on GeoIP can be found here.




回答2:


In addition to the other answers (GeoIP), you may try to analyze the Accept-Language header field and serve the content to users that accept finnish language.

You can modify the following function to parse Accept-Language header in PHP:

  • How to select content type from HTTP Accept header in PHP



回答3:


As yet another alternative, you can download one of the SQL databases here and use it to resolve an IP address to a location:

http://www.ipinfodb.com/ip_database.php

Also, they offer an API that does the same thing, but this may not be optimal if you're getting a lot of traffic.




回答4:


Here is a pointer to MaxMind GeoIP Country Database. http://www.maxmind.com/app/country. It's about $50.00 and comes with a PHP library for accessing the information.




回答5:


You have a few bets you can try:

  • convert the IP to a geographic location (PEAR: Net_GeoIP)
  • check the requested language that is used in the browser, and use that. Problem is, a lot of people just have 'english' setup, so this won't always work.

Hope this helps!



来源:https://stackoverflow.com/questions/1088552/how-can-i-show-different-content-to-website-visitors-from-a-specific-country-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!