What is the difference between HTTP_HOST and SERVER_NAME in PHP?

前端 未结 10 2310
青春惊慌失措
青春惊慌失措 2020-11-22 07:07

What is the difference between HTTP_HOST and SERVER_NAME in PHP?

where:

  • HTTP_HOST === $_SERVER[\'HTTP_HOST\'
10条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 07:58

    As balusC said SERVER_NAME is not reliable and can be changed in apache config , server name config of server and firewall that can be between you and server.

    Following function always return real host (user typed host) without port and it's almost reliable:

    function getRealHost(){
       list($realHost,)=explode(':',$_SERVER['HTTP_HOST']);
       return $realHost;
    }
    

提交回复
热议问题