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).
Well, I'm (almost) sure that without making use of the
$_SERVERsuperglobal keys, providing a alternative way to figure outPATH_INFOis just impossible, that being said lets first list all of the $_SERVER keys that we may possibly use: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:
Regarding your comment to Anthonys answer:
I'm running LightTPD/1.4.20-1 (Win32) with PHP 5.3.0 as CGI,
cgi.fix_pathinfo = 1and$_SERVER['REQUEST_URI']is very available to me, I also remember using that same variable back in the days when no one usedmod_rewriteso my honest humble guess is that you're plain wrong in this point. Regarding theSCRIPT_FILENAMEkey 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:I'm not trying in being harsh here (and I still believe that there are more solutions) but if
PHP_SELFis the only key you want us to work with (assuming there are no impositions onPHP_SELFitself) there is only one solution left: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:
REQUEST_URIis Apache specific?)PHP_SELFvsPATH_INFOvsSCRIPT_NAMEvsREQUEST_URI