Returns the requested URL path of the page being viewed.
Examples:
The requested Drupal URL path.
function request_path() {
static $path;
if (isset($path)) {
return $path;
}
// Get the part of the URI between the base path of the Drupal installation
// and the query string, and unescape it.
$request_path = request_uri(TRUE);
$base_path_len = strlen(rtrim(dirname($_SERVER['SCRIPT_NAME']), '\\/'));
$path = substr(urldecode($request_path), $base_path_len + 1);
// Depending on server configuration, the URI might or might not include the
// script name. For example, the front page might be accessed as
// http://example.com or as http://example.com/index.php, and the "user"
// page might be accessed as http://example.com/user or as
// http://example.com/index.php/user. Strip the script name from $path.
$script = basename($_SERVER['SCRIPT_NAME']);
if ($path == $script) {
$path = '';
}
elseif (strpos($path, $script . '/') === 0) {
$path = substr($path, strlen($script) + 1);
}
// Extra slashes can appear in URLs or under some conditions, added by Apache,
// so normalize.
$path = trim($path, '/');
return $path;
}