Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Difference between PHP $_SERVER['HTTP_HOST'] and $_SERVER['SERVER_NAME']

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 592
    Comment on it

    Hello Reader's! In working PHP you might have seen the two common syntax $_SERVER['HTTP_HOST'] and $_SERVER['SERVER_NAME']. They share similar name but they work different.
    $_SERVER['SERVER_NAME'] gives the value of the server name as defined in host configuration (lets say example Apache the Apache .conf file) and $_SERVER['HTTP_HOST'] gives you the domain name through which the current request is being fulfilled, here user is more related to request.


    HTTP_HOST is the header from the current request, if it exists. Whereas SERVER_NAME is the name of the server host under which the current script is executing. If the script is running on a virtual host then this will be the value defined for that virtual host.

    Let's see the working example below:-

    <?php
    echo $_SERVER['SERVER_NAME'];
    ?>
    

    Output:

    www.findnerd.com
    

    And

    <?php echo $_SERVER['HTTP_HOST']; ?>
    

    Output:-

    localhost:8080
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: