Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 505105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:33:52+00:00 2026-05-13T06:33:52+00:00

I’m seeking a portable way to receive the (handy) $_SERVER[‘PATH_INFO’] variable. After reading a

  • 0

I’m seeking a portable way to receive the (handy) $_SERVER['PATH_INFO'] variable.

After reading a while, it turns out PATH_INFO is originated from CGI/1.1, and my not always be present in all configuration.

What is the best (mostly security-wise) way to get that variable – apart from extracting it manually (security concern).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:33:52+00:00Added an answer on May 13, 2026 at 6:33 am

    Well, I’m (almost) sure that without making use of the $_SERVER superglobal keys, providing a alternative way to figure out PATH_INFO is just impossible, that being said lets first list all of the $_SERVER keys that we may possibly use:

    • ‘PHP_SELF’
    • ‘QUERY_STRING’
    • ‘SCRIPT_FILENAME’
    • ‘PATH_TRANSLATED’
    • ‘SCRIPT_NAME’
    • ‘REQUEST_URI’
    • ‘PATH_INFO’
    • ‘ORIG_PATH_INFO’

    We obviously need to ignore the last two. Now we should (I don’t know this for a fact, I’m just assuming because you said so) filter all the keys that exist in the link you provided (which BTW is offline ATM), that leaves us with the following keys:

    • ‘PHP_SELF’
    • ‘SCRIPT_FILENAME’
    • ‘REQUEST_URI’

    Regarding your comment to Anthonys answer:

    You are just juggling variables now.
    SCRIPT_FILENAME is a part of the CGI
    spec. It will not be available if
    PATH_INFO is unavailable. As for
    REQUEST_URI, it’s apache’s mod_rewrite
    specific. – LiraNuna

    I’m running LightTPD/1.4.20-1 (Win32) with PHP 5.3.0 as CGI, cgi.fix_pathinfo = 1 and $_SERVER['REQUEST_URI'] is very available to me, I also remember using that same variable back in the days when no one used mod_rewrite so my honest humble guess is that you’re plain wrong in this point. Regarding the SCRIPT_FILENAME key I’m unable to test that one out ATM. Still, if we close our eyes really hard and believe that you’re right that leaves us with only one variable:

    • ‘PHP_SELF’

    I’m not trying in being harsh here (and I still believe that there are more solutions) but if PHP_SELF is the only key you want us to work with (assuming there are no impositions on PHP_SELF itself) there is only one solution left:

    function PATH_INFO()
    {
     if (array_key_exists('PATH_INFO', $_SERVER) === true)
     {
      return $_SERVER['PATH_INFO'];
     }
    
     $whatToUse = basename(__FILE__); // see below
    
     return substr($_SERVER['PHP_SELF'], strpos($_SERVER['PHP_SELF'], $whatToUse) + strlen($whatToUse));
    }
    

    This function should work, however there may be some problems using the __FILE__ constant since it returns the path to the file where the __FILE__ constant is declared and not the path to the requested PHP script, so that’s why the $whatToUse is there for: sou you can replace it with 'SCRIPT_FILENAME' or if you really believe in what you are saying, just use '.php'.

    You should also read this regarding why not to use PHP_SELF.

    If this doesn’t work for you, I’m sorry but I can think of anything else.

    EDIT – Some more reading for you:

    • Drupal request_uri() (why do they keep saying REQUEST_URI is Apache specific?)
    • PHP_SELF vs PATH_INFO vs SCRIPT_NAME vs REQUEST_URI
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.