Well, normally browsers send a "Host: <host of URL typed>" HTTP header to the server when a page is requested. This is actually required in the HTTP 1.1 protocol (NOT required in 1.0). Therefore, you can usually tell what host the page is being requested under by using $_SERVER['HTTP_HOST']
Now, this doesn't have to be sent, so you can't rely on this being 100% effective. For the most part, however, it should work.