Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I check the domain name that has been used to access my server using PHP?

I have several domains that I have changed the name servers for and now I want to be able to check the domain that is hitting my server?

Would be grateful for links to read up on this sort of thing and how to test.

Thanks all

share|improve this question
DNS servers do not "hit" servers. An "nslookup" can be used to query a DNS server. – user1797 Aug 27 '09 at 10:39

I have done something like the following (which redirected depending upon the requesting URL but you can do whatever you need to do)

     $url = $_SERVER['HTTP_HOST'];

     header("Content-type: text/html");
     // depending upon which 'Host' was in the URL,
     // we redirect to different places or nowhere at all
     if ( $url == ''
                || $url == '' ) {
     else if ( $url == ''
            || $url == '' ) {
     // otherwise default
share|improve this answer

I don't think you can tell which name server was used by the client if that is what you are asking. You can only see what the domain was that they requested because it is in the HTTP header. Doing this with PHP should probably be on stackoverflow.

If you are running Apache as your webserver, you can just look at the access_log file, which would be in something like /var/log/httpd/access_log to see which domain they are requesting.

share|improve this answer

Unless I am not understanding the question correctly, you can easily check for what domain is hitting your server using:


Does seem more appropriate for Stack Overflow though...

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.