1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to reference the current site correctly

Discussion in 'PHP' started by briandunning, Oct 31, 2005.

  1. #1
    I often use <?php echo $_SERVER['SERVER_NAME']; ?> for miscellaneous purposes referring to the current site: like in an email, or other things. I do this so it will work on my development server (192.168.1.85) as well as the production server (www.domain.com). Problem is that this always resolves to 'domain.com' instead of 'www.domain.com' even though www.domain.com is what's shown in the browser URL bar.
    SEMrush
    Obivously it would be easy to hack this with some conditional - is there a simpler more elegant solution?
     
    briandunning, Oct 31, 2005 IP
    SEMrush
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,301
    Likes Received:
    2,605
    Best Answers:
    461
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    The $_SERVER superglobal is an array of Apache environment variables, so in theory Apache could be setting it to whatever it wants (my guess is Apache has the site setup to default to domain.com [and not www.domain.com]). I *think* SERVER_NAME can be anything to be honest (you might be able to make it "Acme Site" if you wanted to for example).

    You would be better off using $_SERVER['HTTP_HOST'].
     
    digitalpoint, Oct 31, 2005 IP
    briandunning likes this.
  3. briandunning

    briandunning Active Member

    Messages:
    262
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    98
    #3
    That's my huckleberry.
     
    briandunning, Oct 31, 2005 IP
    sarahk likes this.