开发者

How can I work out using PHP if a domain is .co.uk or .com?

I have two domains with pretty much the same开发者_运维问答 code on both, (version control) but I wanted a little bit of code that would show '(US)' if the viewer was looking at the .com or '(UK)' if the .co.uk, any help welcome...


if (substr($_SERVER['HTTP_HOST'], -4) == ".com") {
    // you're on the .com domain
}
//... etc

Caveat: This relies on the Host: HTTP request header, which may not always be sent. (I don't think it's required, if the server is not using name-based virtual hosts.)

A more solid solution would be to make this a configuration variable of the application, which can be automatically changed upon deployment to either of the servers.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜