homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Is $_SERVER['REQUEST_URI'] always available?

Msg#: 4524488 posted 12:09 pm on Dec 3, 2012 (gmt 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
$_SERVER['REQUEST_URI'] is always available? (It's important, because I use this variable to find out what page was requested.)

Greetings, Zuulo



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

Msg#: 4524488 posted 1:57 pm on Dec 3, 2012 (gmt 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>';


Msg#: 4524488 posted 7:42 pm on Dec 5, 2012 (gmt 0)

Thank you g1smd!
[Cleaning: There's only a limited number of pages, so I use a whitelist ->
if(in_array($requested, $allowed)){ ... }.]
Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved