web hosting
build a website

Target domain name for specific code in PHP template

Aug 16, 2015   //   by Anthony Devine   //   Website Development tips  //  No Comments

If your site uses 1 template for multiple domains such a foreign sites you may need some things to be different such as tracking codes. One way to do that is by using the following PHP code in the head of your site. This says if your server uses any of the following domain then do the following in the { }

<?php

                    if($_SERVER['HTTP_HOST'] == "www.domain.com" ||
                    $_SERVER['HTTP_HOST'] == "www.domain.co.uk" ||
                    $_SERVER['HTTP_HOST'] == "domain.com" ||
                    $_SERVER['HTTP_HOST'] == "domain.co.uk" ||
                    $_SERVER['HTTP_HOST'] == "test.domain.co.uk" ||
                    $_SERVER['HTTP_HOST'] == "www.test.domain.co.uk" ||
                    $_SERVER['HTTP_HOST'] == "test.domain.com" ||
                    $_SERVER['HTTP_HOST'] == "www.test.domain.com"){
                        ?>
<?php   }  ?>