6

How do I check if the URL accessing the page is the original URL or if it's a CNAME record.

For example, I have a site domain.com. Users can setup a CNAME where they link www.otherdomain.com to our site domain.com.

From our server point of view, how can I detect if the URL accessing the page is the actual one (domain.com) or the CNAME one (www.otherdomain.com)?

1
  • Does this sort of think require a dedicated IP?
    – JBithell
    Nov 9, 2014 at 8:11

3 Answers 3

11

I think you have to query a DNS to know it, since this information does not usually come in request headers.

Take a look at the dns_get_record and checkdnsrr functions in PHP documentation.

1
  • dns_get_record is the correct answer. I got it to work. Thanks.
    – Pinkie
    Nov 22, 2011 at 20:35
2

You can use PHPDNS class library to find out what kind of DNS record is a given url.

$answer->results[x]->typeid //Textual record type ID (A, MX, CNAME etc)
2

If you're checking on URLs, you can use $_SERVER['HTTP_HOST'] in PHP. That's the requested host from the URL (eg. http://otherdomain.com/blah.php would make the server var be otherdomain.com). $_SERVER['SERVER_NAME'] is the configured servername in the httpd.conf.

If HTTP_HOST != SERVER_NAME, the remote user is almost certainly using an alias of some sort to access the site.

1
  • Both HTTP_HOST and HTTP_NAME are giving me otherdomain.com
    – Pinkie
    Nov 22, 2011 at 19:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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