Request.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. class Request {
  3. // @usage: Request::isHttps();
  4. public static function isHttps() {
  5. // method for previous apache: !empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'
  6. // [forwarded] => 1
  7. // [HTTP_X_FORWARDED_PROTO] => https
  8. // [HTTP_X_FORWARDED_PORT] => 443
  9. if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && 'https' == $_SERVER['HTTP_X_FORWARDED_PROTO']) {
  10. return true;
  11. } else if (!empty($_SERVER['HTTPS']) && 'on' == $_SERVER['HTTPS']) {
  12. return true;
  13. }
  14. return false;
  15. }
  16. // @usage: Request::getScriptUri();
  17. public static function getScriptUri() {
  18. // [SCRIPT_URI] => http://biuro.biall-net.pl:34543/dev-pl/se-master/wfs-qgis.php/default_db/
  19. // [SCRIPT_URL] => /dev-pl/se-master/wfs-qgis.php/default_db/
  20. // [SCRIPT_NAME] => /dev-pl/se-master/wfs-qgis.php
  21. // [HTTP_HOST] => biuro.biall-net.pl
  22. $uri = (Request::isHttps())? 'https://' : 'http://';
  23. $uri .= "{$_SERVER['HTTP_HOST']}{$_SERVER['SCRIPT_URL']}";
  24. return $uri;
  25. }
  26. // @usage: Request::getPathUri();
  27. public static function getPathUri() {
  28. // [SCRIPT_URI] => http://biuro.biall-net.pl:34543/dev-pl/se-master/wfs-qgis.php/default_db/
  29. // [SCRIPT_URL] => /dev-pl/se-master/wfs-qgis.php/default_db/
  30. // [SCRIPT_NAME] => /dev-pl/se-master/wfs-qgis.php
  31. // [HTTP_HOST] => biuro.biall-net.pl
  32. $uri = (Request::isHttps())? 'https://' : 'http://';
  33. $uri .= $_SERVER['HTTP_HOST'];
  34. $scriptPath = '';
  35. $scriptName = $_SERVER['SCRIPT_NAME'];
  36. if ('/' == substr($scriptName, -1)) {
  37. $scriptPath = $scriptName;
  38. } else {
  39. $scriptPathEx = explode('/', $scriptName);
  40. array_pop($scriptPathEx);
  41. $scriptPath = implode('/', $scriptPathEx) . '/';
  42. }
  43. $uri .= $scriptPath;
  44. return $uri;
  45. }
  46. // @usage: Request::getRewriteTaskPath();
  47. public static function getRewriteTaskPath() {
  48. $reqUri = $_SERVER['REQUEST_URI'];
  49. $reqScript = $_SERVER['SCRIPT_NAME'];
  50. $taskPath = str_replace($reqScript, '', $reqUri);
  51. return $taskPath;
  52. }
  53. // @usage: Request::getRequestBody();
  54. public static function getRequestBody() {
  55. static $requestBody = null;
  56. if (null === $requestBody) {
  57. $requestBody = file_get_contents("php://input");
  58. }
  59. return $requestBody;
  60. }
  61. }