PHP getting full server name including port number and protocol

前端 未结 9 1454
暗喜
暗喜 2020-12-16 12:00

In PHP, is there a reliable and good way of getting these things:

Protocol: i.e. http or https Servername: e.g. localhost Portnumber: e.g. 8080

9条回答
  •  时光取名叫无心
    2020-12-16 12:39

    Why don't you get full url like this

    strtolower(array_shift(explode("/",$_SERVER['SERVER_PROTOCOL'])))."://".$_SERVER['SERVER_NAME'];
    

    or (If you want host name from HTTP)

    strtolower(array_shift(explode("/",$_SERVER['SERVER_PROTOCOL'])))."://".$_SERVER['HTTP_HOST'];
    

提交回复
热议问题