Php server

Discussion in 'PHP' started by roice, Jan 10, 2011.

  1. #1
    Hello,
    What is the different between
    $_SERVER['SERVER_NAME'];
    and
    $_SERVER['HTTP_HOST'];
    ?

    thanks
     
    roice, Jan 10, 2011 IP
  2. Zetiz

    Zetiz Active Member

    Messages:
    668
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #2
    $_SERVER[HTTP_HOST] is derived from the incoming HTTP request.But $_SERVER[SERVER_NAME] is the predefined name of the server in the configuration file.Generally this is the name of the server under which a PHP script is being executed. Also $_SERVER[HTTP_HOST] refers to the headers from the current request, if any. Hope this helps you.
     
    Last edited: Jan 10, 2011
    Zetiz, Jan 10, 2011 IP
  3. deepakg

    deepakg Peon

    Messages:
    48
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    $_SERVER['SERVER_NAME'] is based on your web servers' config file (Apache2 in my case), and varies depending on a few directives: (1) VirtualHost, (2) ServerName, (3) UseCanonicalName, etc.

    $_SERVER['HTTP_HOST'] is based on the request from the client.
     
    deepakg, Jan 10, 2011 IP
  4. roice

    roice Peon

    Messages:
    200
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    So which one is better to use if I want to get the domain name of my website?
     
    roice, Jan 10, 2011 IP
  5. Zetiz

    Zetiz Active Member

    Messages:
    668
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #5
    Use $_SERVER['HTTP_HOST'] to get the domain name of the site you want.
     
    Zetiz, Jan 10, 2011 IP
  6. roice

    roice Peon

    Messages:
    200
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Ok
    thanks...
     
    roice, Jan 10, 2011 IP
  7. Zetiz

    Zetiz Active Member

    Messages:
    668
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #7
    Welcome... :)
     
    Zetiz, Jan 10, 2011 IP