如何向PHP中的特定国家/地区的网站访问者显示不同的内容?

时间:2022-11-29 22:48:50

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?

在我的Wordpress博客上,我想在所有页面上向芬兰人展示其他内容。非常像printfriendly.com上屏幕左边的反馈按钮。如何使用PHP最可靠地实现这一目标?

5 个解决方案

#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.

我的建议是使用PHP GeoIP功能来确定基于IP的用户位置,并根据它提供适当的内容。

More information on GeoIP can be found here.

有关GeoIP的更多信息,请访问此处。

#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.

除了其他答案(GeoIP)之外,您可以尝试分析Accept-Language标头字段并将内容提供给接受芬兰语的用户。

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

您可以修改以下函数来解析PHP中的Accept-Language标头:

#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:

作为另一种选择,您可以在此处下载其中一个SQL数据库并使用它来解析某个位置的IP地址:

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.

此外,它们提供的API也可以执行相同的操作,但如果您获得大量流量,这可能不是最佳选择。

#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.

这是指向MaxMind GeoIP国家数据库的指针。 http://www.maxmind.com/app/country。它大约是50美元,附带一个用于访问信息的PHP库。

#5


You have a few bets you can try:

你可以试试几个赌注:

  • convert the IP to a geographic location (PEAR: Net_GeoIP)
  • 将IP转换为地理位置(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!

希望这可以帮助!

#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.

我的建议是使用PHP GeoIP功能来确定基于IP的用户位置,并根据它提供适当的内容。

More information on GeoIP can be found here.

有关GeoIP的更多信息,请访问此处。

#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.

除了其他答案(GeoIP)之外,您可以尝试分析Accept-Language标头字段并将内容提供给接受芬兰语的用户。

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

您可以修改以下函数来解析PHP中的Accept-Language标头:

#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:

作为另一种选择,您可以在此处下载其中一个SQL数据库并使用它来解析某个位置的IP地址:

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.

此外,它们提供的API也可以执行相同的操作,但如果您获得大量流量,这可能不是最佳选择。

#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.

这是指向MaxMind GeoIP国家数据库的指针。 http://www.maxmind.com/app/country。它大约是50美元,附带一个用于访问信息的PHP库。

#5


You have a few bets you can try:

你可以试试几个赌注:

  • convert the IP to a geographic location (PEAR: Net_GeoIP)
  • 将IP转换为地理位置(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!

希望这可以帮助!