function current_path -

Public

includes/path.inc, line 354 https://api.drupal.org/api/drupal/includes%21path.inc/function/current_p...

function current_path

7 path.inc current_path()
Return the current 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 "node/306" as opposed to the path alias.
This function is not available in hook_boot() so use $_GET['q'] instead. However, be careful when doing that because in the case of Example #3 $_GET['q'] will contain "path/alias". If "node/306" is needed, calling drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL) makes this function available.

Return value

The current Drupal URL path.

See also

request_path()

</> CopyGet raw version
php
  1. function current_path() {
  2. return $_GET['q'];
  3. }
  4.  
  5. // Will also return URLs without the language prefix.
  6.  
  7. //and here's how to get the alias:
  8.  
  9. $path = current_path();
  10. $path_alias = drupal_lookup_path('alias',$path);

function request_path

7 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

current_path()

3 calls to request_path()
File

includes/bootstrap.inc, line 2809

</> CopyGet raw version
php
  1. /**
  2. * $GLOBALS['base_url'] => http://example.com/drupal
  3. * base_path() => /drupal/
  4. * request_uri() => /drupal/documentation?page=1
  5. * request_path() => documentation
  6. * current_path() => node/26419
  7. **/
  8.  
  9. function request_path() {
  10. static $path;
  11.  
  12. if (isset($path)) {
  13. return $path;
  14. }
  15.  
  16. if (isset($_GET ['q']) && is_string($_GET ['q'])) {
  17. // This is a request with a ?q=foo/bar query string. $_GET['q'] is
  18. // overwritten in drupal_path_initialize(), but request_path() is called
  19. // very early in the bootstrap process, so the original value is saved in
  20. // $path and returned in later calls.
  21. $path = $_GET ['q'];
  22. }
  23. elseif (isset($_SERVER ['REQUEST_URI'])) {
  24. // This request is either a clean URL, or 'index.php', or nonsense.
  25. // Extract the path from REQUEST_URI.
  26. $request_path = strtok($_SERVER ['REQUEST_URI'], '?');
  27. $base_path_len = strlen(rtrim(dirname($_SERVER ['SCRIPT_NAME']), '\/'));
  28. // Unescape and strip $base_path prefix, leaving q without a leading slash.
  29. $path = substr(urldecode($request_path), $base_path_len + 1);
  30. // If the path equals the script filename, either because 'index.php' was
  31. // explicitly provided in the URL, or because the server added it to
  32. // $_SERVER['REQUEST_URI'] even when it wasn't provided in the URL (some
  33. // versions of Microsoft IIS do this), the front page should be served.
  34. if ($path == basename($_SERVER ['PHP_SELF'])) {
  35. $path = '';
  36. }
  37. }
  38. else {
  39. // This is the front page.
  40. $path = '';
  41. }
  42.  
  43. // Under certain conditions Apache's RewriteRule directive prepends the value
  44. // assigned to $_GET['q'] with a slash. Moreover we can always have a trailing
  45. // slash in place, hence we need to normalize $_GET['q'].
  46. $path = trim($path, '/');
  47.  
  48. return $path;
  49. }

equivalent for filesystem path

https://api.drupal.org/api/drupal/includes%21common.inc/function/base_pa...

I wrote a small function to find the local filesystem path, by walking step for step up, until its in the root directory and finds the relative path to bootstrap.inc.

</> CopyGet raw version
php
  1. /**
  2.   * Returns the base filesystem path of the Drupal installation.
  3.   *
  4.   * @author: Radon8472
  5.   * @version: 1.0 (2013-10-19)
  6.   *
  7.   * @return string: absolute local filesystem path of the Drupal installation.
  8.   */
  9. function filesystem_base_path()
  10. {
  11. if(!isset($GLOBALS['filesystem_base_path']))
  12. {
  13. $search = "includes".DIRECTORY_SEPARATOR."bootstrap.inc";
  14.  
  15.  
  16. // Walk directories up until we find the $search-path (which is relative to root)
  17. for($path=dirname(__FILE__); !file_exists($path.DIRECTORY_SEPARATOR.$search); $path.= DIRECTORY_SEPARATOR."..")
  18. {
  19. // no need to do anything
  20. }
  21. // store the path if it one was found
  22. $GLOBALS['filesystem_base_path'] = realpath($path);
  23. }
  24. return $GLOBALS['filesystem_base_path'];
  25. }