$addressbar = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER

Discussion in 'PHP' started by johnsmith153, May 9, 2008.

  1. #1
    <?php
    $addressbar = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    echo $addressbar;
    ?>

    Is this reliable? I need to grab certain parts of the address bar in my php code.

    If I can not get the address bar info, my site would hardly work.

    I have heard how sometimes php cant pick up on this info, but I may be thinking of something else.

    I am not bothered about security (as I know these things can easily be changed) - if someone wants to prevent it being sent then they just wont see my site - however I want to ensure genuine users are not prevented by no fault of their own.

    I.e AOL users for example get a weird experience / IP address change etc. Just want to make sure there isn't some sort of thing where address bar info can not be picked up and by no fault of the user.

    Just a quick YES would be fine if I should go ahead with this. If I see a load of YES posts that is enough for me. Although if not sure, don't post. Thanks.
     
    johnsmith153, May 9, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Those should work fine. If you're ever in question for a specific server, open up a phpinfo() and look under PHP Variables.
     
    jestep, May 9, 2008 IP
  3. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #3
    Yes, it'll always work. The server variables are always assigned by PHP at runtime and will always be present, and can never be altered.

    Jay
     
    jayshah, May 9, 2008 IP