Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,057
    Thanks
    25
    Thanked 0 Times in 0 Posts

    Question about $_SERVER['REQUEST_URI']

    Does the function $_SERVER['REQUEST_URI'] return everything I need to return back to a page?

    In other words, will it include the domain name plus the file path like this...
    Code:
    http://www.Debbie.com/some/path/to/my/script.php
    Sincerely,


    Debbie

  • #2
    Regular Coder Linux_Sage's Avatar
    Join Date
    Mar 2014
    Location
    Sterling,VA
    Posts
    105
    Thanks
    0
    Thanked 10 Times in 10 Posts
    According to the documentation:
    Code:
    'REQUEST_URI'
        The URI which was given in order to access this page; for instance, '/index.html'.
    Source: PHP: $_SERVER - Manual

  • #3
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,057
    Thanks
    25
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Linux_Sage View Post
    According to the documentation:
    Code:
    'REQUEST_URI'
        The URI which was given in order to access this page; for instance, '/index.html'.
    Source: PHP: $_SERVER - Manual
    Uh, I already looked up the Manual, and it wasn't clear to me, so I asked here...

  • #4
    Regular Coder Linux_Sage's Avatar
    Join Date
    Mar 2014
    Location
    Sterling,VA
    Posts
    105
    Thanks
    0
    Thanked 10 Times in 10 Posts
    No, it will not include the domain name and as long as the link isn't external it should provide a usable path.

  • #5
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,057
    Thanks
    25
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Linux_Sage View Post
    No, it will not include the domain name and as long as the link isn't external it should provide a usable path.
    Then please help me understand this better.

    Here is what I am doing...

    I have a script which displays the outcome of actions (i.e. success and failure messages).

    As part of one of my scripts, I have this code in the "outcome.php" script...
    PHP Code:
        echo '<a class="button" href="' BASE_URL $returnToPage '">Return to Article</a>'

    To clean up my code, I was hoping to get rid of BASE_URL.

    If I remove it, when I hover over the "Return to Article" button, it shows a proper URL like this...
    Code:
    http://local.debbie/articles/edit-comment/save-your-taxes-for-a-cpa/212

    So that is why I was confused, because $returnToPage is set to $_SERVER['REQUEST_URI'] in my other script.

    First of all, why does the domain part still appear after I drop BASE_URL which is a constant defining my, well, Base URL?!


    Secondly, what should I do as far as keeping or dropping BASE_URL in the sample code above?

    All of this code is either being run on my laptop for dev, or on my web host for my website. (There will never be any 3rd party websites involved.)

    I just want to keep my code secure and make sure it doesn't break.

    Follow me?


    Debbie

  • #6
    Regular Coder Linux_Sage's Avatar
    Join Date
    Mar 2014
    Location
    Sterling,VA
    Posts
    105
    Thanks
    0
    Thanked 10 Times in 10 Posts
    There's no real reason to include the entire path including the domain if what you're pointing to is local. You'd only need to do that if what you're pointing to is external to your site.

    Even if your link was nothing more than:
    Code:
    <a href="/articles/edit-comment/save-your-taxes-for-a-cpa/212">whatever</a>
    Your domain will still be there. Perhaps this will clear things up:
    Absolute vs. Relative Paths/Links | CoffeeCup Software

  • #7
    Regular Coder Linux_Sage's Avatar
    Join Date
    Mar 2014
    Location
    Sterling,VA
    Posts
    105
    Thanks
    0
    Thanked 10 Times in 10 Posts
    Ugh... The spam filter keeps snagging my posts because of the links.

    There's no real reason to include the entire path including the domain if what you're pointing to is local. You'd only need to do that if what you're pointing to is external to your site.

    Even if your link was nothing more than:
    Code:
    <a href="/articles/edit-comment/save-your-taxes-for-a-cpa/212">whatever</a>
    Your domain will still be there.

  • #8
    Regular Coder Linux_Sage's Avatar
    Join Date
    Mar 2014
    Location
    Sterling,VA
    Posts
    105
    Thanks
    0
    Thanked 10 Times in 10 Posts
    Perhaps this will clear things up:
    Absolute vs. Relative Paths/Links | CoffeeCup Software

  • #9
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,057
    Thanks
    25
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Linux_Sage View Post
    Thanks for the link, but not very well written.

    It seems to me that what is most important is that $returnToPage = $_SERVER['REQUEST_URI'] will always yield a path that starts with a '/' and since I am placing that link in an HTML reference, HTML will always treat the '/' at the Web Root for my website, right?

    Code:
    	$returnToPage = '/articles/edit-comment/save-your-taxes-for-a-cpa/212';
    	echo '<a class="button" href="' . BASE_URL . $returnToPage . '">Return to Article</a>';

    So, in the end, having the extra BASE_URL adds no extra value, correct?

    Sincerely,


    Debbie


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •