开发者

How to determine default Accept-Language header based on IP (country code)?

I want like to enhance spam protection on my site. I've found out that after being banned by ip bots don't change the Accept-L开发者_运维技巧anguage and Accept-Charset http headers (so most of spam comes with windows-1251 accept-charset). I understand that there may be normal users with unordinary preferences, but anyways, how can I determine which charset and language headers are most popular in a particular country? TIA


This answer has two parts: determining where your user comes from, and what language they speak. To determine where they come from, you can use a service such as hostip.info, which has an API which takes an IP address and returns a country code. Second, you would need a list such as this one to translate the country code into a language code. You could use either a full database or a simple dict to store the mapping.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜