function request_uri() - Returns the equivalent of Apache's $_SERVER['REQUEST_URI'] variable

Public

bootstrap.inc

</> CopyGet raw version
php
  1. /**
  2.  * Returns the equivalent of Apache's $_SERVER['REQUEST_URI'] variable.
  3.  *
  4.  * Because $_SERVER['REQUEST_URI'] is only available on Apache, we generate an
  5.  * equivalent using other environment variables.
  6.  */
  7. function request_uri() {
  8. if (isset($_SERVER['REQUEST_URI'])) {
  9. $uri = $_SERVER['REQUEST_URI'];
  10. }
  11. else {
  12. if (isset($_SERVER['argv'])) {
  13. $uri = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['argv'][0];
  14. }
  15. elseif (isset($_SERVER['QUERY_STRING'])) {
  16. $uri = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING'];
  17. }
  18. else {
  19. $uri = $_SERVER['SCRIPT_NAME'];
  20. }
  21. }
  22. // Prevent multiple slashes to avoid cross site requests via the Form API.
  23. $uri = '/' . ltrim($uri, '/');
  24.  
  25. return $uri;
  26. }