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...
+5
A:
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.
Ben James
2009-12-04 11:28:02
Well, given the client has no idea if the server is using VH or not, I guess it will send it anyway, otherwise the server will not be able to know what to show.
Stefano Borini
2009-12-04 11:46:30
Stefano: that is still no reason to make assumptions or to rely on it. The developer should still assume that it may not be sent, because it is possible.
Ben James
2009-12-04 11:51:36