Best way to get hostname with php

前端 未结 6 2006
别跟我提以往
别跟我提以往 2020-12-05 03:51

I have a php application that is installed on several servers and all of our developers laptops. I need a fast and reliable way to get the server\'s hostname or some other

6条回答
  •  既然无缘
    2020-12-05 04:27

    The accepted answer gethostname() may infact give you inaccurate value as in my case

    gethostname()         = my-macbook-pro     (incorrect)
    $_SERVER['host_name'] = mysite.git         (correct)
    

    The value from gethostname() is obvsiously wrong. Be careful with it.

    Update as corrected by the comment

    Host name gives you computer name, not website name, my bad. My result on local machine is

    gethostname()         = my-macbook-pro     (which is my machine name)
    $_SERVER['host_name'] = mysite.git         (which is my website name)
    

提交回复
热议问题