Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies


Is $_SERVER['REQUEST_URI'] always available?

12:09 pm on Dec 3, 2012 (gmt 0)

New User

joined:Oct 12, 2012
votes: 0

I use code like
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.php

to handle all requests for pages in my index.php file. Can I be sure, that
is always available? (It's important, because I use this variable to find out what page was requested.)

Greetings, Zuulo
1:57 pm on Dec 3, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
votes: 0

It should always be there, or a variant of it, but it might easily contain something quite malicious so it should be cleaned and verified before doing anything else with it.

I find this code quite useful:

if( !empty( $GLOBALS[ '_SERVER' ])) {
} elseif( !empty( $GLOBALS[ 'HTTP_SERVER_VARS' ])) {
} else {

$requestHost= ${$_SERVER_ARRAY}[ 'SERVER_NAME' ];

$datetime= gmdate( 'Y-m-d H:i:s O' );

$remoteIP= ${$_SERVER_ARRAY}[ 'REMOTE_ADDR' ];

$requestURI= ${$_SERVER_ARRAY}[ 'REQUEST_URI' ];

$referer= ( isset( ${$_SERVER_ARRAY}[ 'HTTP_REFERER' ]))
: '<unknown referer>';

$userAgent= ( isset( ${$_SERVER_ARRAY}[ 'HTTP_USER_AGENT' ]))
: '<unknown user agent>';
7:42 pm on Dec 5, 2012 (gmt 0)

New User

joined:Oct 12, 2012
votes: 0

Thank you g1smd!
[Cleaning: There's only a limited number of pages, so I use a whitelist ->
if(in_array($requested, $allowed)){ ... }