Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Php Cname redirection

Recently I’ve been thinking about such a question: how to use php to recognize that a site is referenced with a CNAME record, and if so, redirect it to a specific document?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$_SERVER['SERVER_NAME'] contains the domain name of the site being served, which you can plug into dns_get_record(), filtered to get only CNAME records. So, if the domain name that was used to view the site is a CNAME, the result will not be empty, which you can use as a conditional for your redirect. I can’t think of any use case where this would be desired, but something like this:

if (!empty(dns_get_record($_SERVER['SERVER_NAME'], DNS_CNAME))) {
    header('Location: <whatever>');
    exit;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading