Forum Moderators: coopster

Message Too Old, No Replies

Some parts of $_SERVER array unavailable

Can I turn them on from within a script?

         

MatthewHSE

9:28 pm on Jan 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I needed to use $_SERVER["HTTP_REFERER"] or $_SERVER["DOCUMENT_URI"] in a script I'm writing, but neither of those seem to be available on my server. Trying to use them returns the "Undefined index" error. I tried running a foreach loop through the $_SERVER array and found that neither HTTP_REFERER or DOCUMENT_URI were present.

So my question is, can I "turn them on" from within the PHP script itself, similar to setting the include path with php_ini()?

Thanks,

Matthew

mincklerstraat

6:25 pm on Jan 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not quite sure why you'd want to 'turn them off' - to avoid these errors? If they are undefined, they're undefined - you'll still get the errors when you have error reporting set to E_ALL. If this is on a site that's already deployed, it isn't a good idea to have error reporting on-screen at all, as it can give clues to scriptkiddies - best to find some way to log your errors, and quickest way to get the errors off-screen now is just to use
error_reporting(0);

What you could always do if you can't avoid the parts of the script that refer to these parts of the $_SERVER array, but don't want the errors, and don't really care what the script is doing with them, is to set these yourself - the $_SERVER array is a variable, after all - this is almost never done, but I tried it ages ago and it worked. The most reasonable thing, though, would just be to remove those lines of your script which use these variables, if there aren't too many to locate.

Birdman

6:51 pm on Jan 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>mincklerstraat

Actually, he said "turn them on", not off.

>MatthewHSE

Those vars are very common but none are guaranteed to be. They are set by the server, so if you want them to be available you could do it in the server config I suppose. Also, I believe it's usually REQUEST_URI, rather than DOCUMENT_URI.

regards

From PHP.net


Server variables: $_SERVER [us3.php.net]

Note: Introduced in 4.1.0. In earlier versions, use $HTTP_SERVER_VARS.

$_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the webserver. There is no guarantee that every webserver will provide any of these; servers may omit some, or provide others not listed here. That said, a large number of these variables are accounted for in the CGI 1.1 specification, so you should be able to expect those.

jatar_k

7:09 pm on Jan 26, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



also take a look at phpinfo, there is a setting for variables_order [ca3.php.net], if there is no S in there then it is turned off.