开发者

Grabbing entry domain for a site

I have several domains that point to the same site, some of them ending in ".br" (domain for Brazil, thus for portuguese speakers)

I want to detect from what domain the person came (.br or not) and load the correct landuage...

I can use PHP, JavaScript or standard HTML/CSS etc... Ho开发者_开发知识库w I do it? (and with what?)


On the server side, use the HTTP_HOST variable which is basically the Host header and a fool-proof way of checking the host the request was sent to.

$_SERVER['HTTP_HOST']

See this question for a nice comparison between SERVER_NAME and the HTTP_HOST variables.

On the client side, use document.domain. For this page - https://developer.mozilla.org/en/document.domain, the value of document.domain is

"developer.mozilla.org"


$_SERVER['HTTP_REFERER'] should get that information. But this is not a sure fire way. Some people have the referrer turned off or spoofed in their browsers etc. This is the only way that I would know how, unless you can append get data to the urls on the domain to set the language etc. Then you just check for that get data.


If you are on PHP5.3+ you can use

Locale::acceptFromHttp — Tries to find out best available locale based on HTTP "Accept-Language" header

If not, you can still determine it from Accept-Language header yourself. Using the Accept Header should be somewhat more reliable than using the TLD, especially if you also need to use any of the other intl extensions.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜