Undefined index HTTP_HOST even though it is checked

前端 未结 5 2269
栀梦
栀梦 2021-02-18 13:17

Here\'s the code:

if (isset($_SERVER[\'HTTP_HOST\']) === TRUE) {
  $host = $_SERVER[\'HTTP_HOST\'];
}

How is it possible to get an \"Undefined

5条回答
  •  南方客
    南方客 (楼主)
    2021-02-18 14:15

    An bad implemented browser can omit send que host header information, try this example:

    telnet myphpserver.com 80
    > GET / 
    

    in this case $_SERVER['HTTP_HOST'] not have assigned value, in this case u can use $_SERVER['SERVER_NAME'] but only if $_SERVER['HTTP_HOST'] is empty, because no is the same.

提交回复
热议问题