Displaying domain name.

Discussion in 'PHP' started by zelphics, Oct 17, 2009.

  1. #1
    Is it possible to print the name of the domain where a file exists with PHP? I want to upload the file to a website, say websites.com, and when i view the file i want it to just say "websites.com", without writing echo "websites.com";.

    Any suggestions on how i should write this?
     
    zelphics, Oct 17, 2009 IP
  2. chadsmith

    chadsmith Peon

    Messages:
    82
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    echo $_SERVER['SERVER_NAME'];
    PHP:
     
    chadsmith, Oct 17, 2009 IP
  3. Brandon_R

    Brandon_R Peon

    Messages:
    330
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The superglobal $_SERVER['HTTP_HOST'] should contain the domain url.

    NON WWW
    
    $domain = parse_url($_SERVER['HTTP_HOST']);
    echo $domain['host'];
    
    PHP:
    OR WWW

    
    $domain = parse_url($_SERVER['HTTP_HOST']);
    echo 'www.' .'$domain['host']';
    
    PHP:
    OR http://www.

    
    $domain = parse_url($_SERVER['HTTP_HOST']);
    echo 'http://www.' .'$domain['host']';
    
    PHP:
    I parsed the URL for all three of them because if a visitor is visiting either the www or non www version of the website you can still get the same result.
     
    Brandon_R, Oct 17, 2009 IP
  4. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #4
    mastermunj, Oct 18, 2009 IP