| 7 bootstrap.inc | request_path() |
| 8 bootstrap.inc | request_path() |
Returns the requested URL path of the page being viewed.
Examples:
- http://example.com/node/306 returns "node/306".
- http://example.com/drupalfolder/node/306 returns "node/306" while base_path() returns "/drupalfolder/".
- http://example.com/path/alias (which is a path alias for node/306) returns "path/alias" as opposed to the internal path.
- http://example.com/index.php returns an empty string (meaning: front page).
- http://example.com/index.php?page=1 returns an empty string.
Return value
The requested Drupal URL path.
See also
4 calls to request_path()
File
- core/
includes/ bootstrap.inc, line 2674 - Functions that need to be loaded on every Drupal request.
Code
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;
}
Login or register to post comments