Search code examples
phpconditional-statementshttp-host

http_host with and without www


I have a message to appear in PHP if the domain going to is outside some existing ones already redirecting to the account.

For example, the command I am trying to run if the domain is www or non www is:

if( $_SERVER[ 'HTTP_HOST' ] != ('xxx.co.uk' && 'www.xxx.co.uk'))

However, this doesnt seem to work as if I go to xxxx.co.uk (which is another domain pointing to their account) the if content still do not show.

Am obviously missing something obvious with the above?


Solution

  • Try this use " " instead of ' '

    if( $_SERVER[ 'HTTP_HOST' ] != ("xxx.co.uk" && "www.xxx.co.uk"))
    

    If the above one doesn't works try below one

    if( ($_SERVER[ 'HTTP_HOST' ] != "xxx.co.uk") && ($_SERVER[ 'HTTP_HOST' ] != "www.xxx.co.uk"))