An include-file function or constant, instead of PHP_SELF or some other predefined variable throughout a website, will make it easier to "fix" an entire website in case something changes. <?php function true_url_path() { // Pick the predefined variable that works on your server return $_ENV['SCRIPT_URL']; } ?> Or <?php // Pick the predefined variable that works on your server define("TRUE_URL_PATH", $_ENV['SCRIPT_URL']); ?> Gregory Boshoff 31-Jul-2005 05:41 $_SERVER['QUERY_STRING'] Does not contain XHTML 1.1 compliant ampersands i.e. & So you will need to do something like this if you are to use $_SERVER['QUERY_STRING'] in URL's. // XHTML 1.1 compliant ampersands $_SERVER['QUERY_STRING'] = str_replace(array('&', '&'), array('&', '&'), $_SERVER['QUERY_STRING']); New York PHP 24-Jul-2005 09:59 Warning: $_SERVER['PHP_SELF'] can include arbitrary user input. The documentation should be updated to reflect this. The request "http://example.com/info.php/attack%20here" will run /info.php, but in Apache $_SERVER['PHP_SELF'] will equal "/info.php/attack here". This is a feature, but it means that PHP_SELF must be treated as user input. The attack string could contain urlencoded HTML and JavaScript (cross-site scripting) or it could contain urlencoded linebreaks (HTTP response-splitting). The use of $_SERVER['SCRIPT_NAME'] is recommended instead. eustf at hotmail dot com 21-Jul-2005 11:05 REQUEST_URI not defined on Windows XP and IIS 5.1 I have seen different script on the web and in this list but they don't work fully. This one seems to work: if(!isset($_SERVER['REQUEST_URI'])) { $arr = explode("/", $_SERVER['PHP_SELF']); $_SERVER['REQUEST_URI'] = "/" . $arr[count($arr)-1]; if ($_SERVER['argv'][0]!="") $_SERVER['REQUEST_URI'] .= "?" . $_SERVER['argv'][0]; } daniel at softel dot jp 16-Jul-2005 02:43 Note that $php_errormsg may contain a newline character. This can be problematic if you are trying to output it with a JavaScript "alert()" for example. andy dot gajetzki at gmail dot com 06-Jul-2005 09:22 I wanted to be able to embed a variable in the path. This is useful when, for example, images are rendered on the fly and you would like them to have different urls. Here is an illustration: www.somesite.com/image.php/IMAGETEXTHERE |