开发者

Run PHP code on a specific domain only

开发者 https://www.devze.com 2022-12-28 01:26 出处:网络
I need to echo out some specific php code only on the sub-domain of a site. This is where I am so far.

I need to echo out some specific php code only on the sub-domain of a site. This is where I am so far.

<?php
    if($_SERVER['SERVER_N开发者_运维问答AME'] != "http://support.demo.com")
        echo "<?php bb_head(); ?>";
?>

Of course if this worked I'd not be asking a question. Help is appreciated.


Host header in HTTP request is your friend here. It can be accessed through $_SERVER['HTTP_HOST']:

if ($_SERVER['HTTP_HOST'] != 'support.demo.com') {
     ...
}

Documented here.


Yaggo was mostly correct except that you want == instead of != if you want to echo if it matches the submdomain

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号