SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    Confirmed Halfwit
    Join Date
    Oct 1999
    Location
    Vancouver, BC, Canada
    Posts
    983
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to get "canonical hostname"?

    When you do a phpinfo(), you can see the server hostname.

    Can anyone tell me what is the php function to retrieve this value into a script?

    Thanks!

  2. #2
    SitePoint Enthusiast nathanj's Avatar
    Join Date
    Dec 2004
    Location
    Perth, WA, Australia
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could use $_SERVER['HTTP_HOST'] or $_SERVER['SERVER_NAME'] although this is not exactly the same.

  3. #3
    Confirmed Halfwit
    Join Date
    Oct 1999
    Location
    Vancouver, BC, Canada
    Posts
    983
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That will only return the virtual hostname that is running the script. I need the actual real server name..

  4. #4
    SitePoint Enthusiast nathanj's Avatar
    Join Date
    Dec 2004
    Location
    Perth, WA, Australia
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes I know, I have no idea you do this sorry.

    PHP Code:
    <?php

    echo `hostname`;

    ?>
    Would work on a linux system and possibly on a windows system. However this will only return the hostname, so this depends how either machine is configured.

  5. #5
    SitePoint Addict launchcode's Avatar
    Join Date
    Dec 2004
    Location
    Bristol, UK
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If the value your truly want appears on phpinfo, in which section does it appear? Perhaps paste in the line here?
    Richard Davey

    Launchcode
    PHP Security Guide. Think your scripts are secure? Think again.

  6. #6
    Confirmed Halfwit
    Join Date
    Oct 1999
    Location
    Vancouver, BC, Canada
    Posts
    983
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by launchcode
    If the value your truly want appears on phpinfo, in which section does it appear? Perhaps paste in the line here?
    It is the very first line in the php output. It's the line that gives the server name, kernel version, operating system, etc...

    This line also gives the true hostname of the server.

    ??

  7. #7
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  8. #8
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    by the way, that first line in phpinfo() gives the hostname of the machine where PHP was built, not the current hostname where it runs.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •