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.

$_SERVER['SERVER_NAME'] question

Discussion in 'PHP' started by qwikad.com, Oct 25, 2016.

  1. #1
    It's all hypothetical, I am not doing this yet. Let's say I have to get a page URL 5 times using:

    h t t p://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

    1. Is it the only way I can do this? 2. Will it drain the resources? I mean, is it like sending a request to get the same page 6 times (counting the original request) or no?
    qwikad.com, Oct 25, 2016 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Likes Received:
    Best Answers:
    Trophy Points:
    If you're doing it five times, why not just assign it to a static variable?

    $page = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
    And, to be absolutely sure it works regardless, do this:

    $page = ((isset($_SERVER['HTTPS']) ? 'https' : 'http').'://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
    Then you only call it once, and can reuse the variable as needed.
    PoPSiCLe, Oct 25, 2016 IP
    sarahk and qwikad.com like this.
  3. ThePHPMaster

    ThePHPMaster Well-Known Member

    Likes Received:
    Best Answers:
    Trophy Points:
    That is the best way imo.

    No, the values are generated by Apache and send to PHP regardless of you using them or not. There is no cost associated with using them that won't come from using another variable.
    ThePHPMaster, Oct 26, 2016 IP
    sarahk and qwikad.com like this.