Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is _SERVER["CONTEXT_PREFIX"]

Tags:

php

phpinfo() shows a variable named _SERVER["CONTEXT_PREFIX"]. It is not documented at http://www.php.net/manual/en/reserved.variables.server.php.
What exactly is it? Where can I find documentation on all of the $_SERVER[*] variables? There are a few more in that list that are not on the php.net webpage.

EDIT
I see from the comments that this is probably server-dependent. I am using the UniServer stack on windows, but since this is unreliable, I won't depend in this key being present.

Is there a list of which keys are present 99% of the time (that is, in all likely setups)?

like image 874
Baruch Avatar asked Aug 26 '12 10:08

Baruch


1 Answers

It looks like it's new in Apache 2.3.13, according to source control for June 28th. There is also CONTEXT_DOCUMENT_ROOT which appears easier to understand.

"Introduce new context_document_root and context_prefix which provide information about non-global URI-to-directory mappings (from e.g. mod_userdir or mod_alias) to scripts." Source: http://marc.info/?l=apache-cvs&m=130928191414740

It's coming from Apache, and is related to when you can have different mappings between the request URI and different directories, such as when you use http://example.com/~username to access a website under "username"'s web space, so the actual document root will vary.

I presume where it will come in useful is if you specify multiple directory sources for one URI, such as:

Userdir public_html /usr/web 

then you're never sure if the files are at "public_html" or "/usr/web" (as it tries one first, then the other) so the CONTEXT_DOCUMENT_ROOT and CONTEXT_PREFIX help you find it.

Can't see any formal documentation on it yet as 2.3 appears to have been skipped in the docs (http://httpd.apache.org/docs/)


Edit: The comments have answered your other part about what server variables can you rely on (impossible to say). If you find that the "CONTEXT" variables are meeting your needs, then you may need to write a functions that says "if they exist, use them, but if not, use another one".

A common example of this is when you try to (unreliably, I know) get the source protocol. You'll check for the proxy added headers first (X_FORWARDED_PROTO) before you search for HTTPS = 'on'. You may need to do similar if the environment variable just happens to be right on your server.

like image 119
Robbie Avatar answered Oct 02 '22 17:10

Robbie