| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- class Request {
- // @usage: Request::isHttps();
- public static function isHttps() {
- // method for previous apache: !empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'
- // [forwarded] => 1
- // [HTTP_X_FORWARDED_PROTO] => https
- // [HTTP_X_FORWARDED_PORT] => 443
- if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && 'https' == $_SERVER['HTTP_X_FORWARDED_PROTO']) {
- return true;
- } else if (!empty($_SERVER['HTTPS']) && 'on' == $_SERVER['HTTPS']) {
- return true;
- }
- return false;
- }
- // @usage: Request::getScriptUri();
- public static function getScriptUri() {
- // [SCRIPT_URI] => http://biuro.biall-net.pl:34543/dev-pl/se-master/wfs-qgis.php/default_db/
- // [SCRIPT_URL] => /dev-pl/se-master/wfs-qgis.php/default_db/
- // [SCRIPT_NAME] => /dev-pl/se-master/wfs-qgis.php
- // [HTTP_HOST] => biuro.biall-net.pl
- $uri = (Request::isHttps())? 'https://' : 'http://';
- $uri .= "{$_SERVER['HTTP_HOST']}{$_SERVER['SCRIPT_URL']}";
- return $uri;
- }
- // @usage: Request::getPathUri();
- public static function getPathUri() {
- // [SCRIPT_URI] => http://biuro.biall-net.pl:34543/dev-pl/se-master/wfs-qgis.php/default_db/
- // [SCRIPT_URL] => /dev-pl/se-master/wfs-qgis.php/default_db/
- // [SCRIPT_NAME] => /dev-pl/se-master/wfs-qgis.php
- // [HTTP_HOST] => biuro.biall-net.pl
- $uri = (Request::isHttps())? 'https://' : 'http://';
- $uri .= $_SERVER['HTTP_HOST'];
- $scriptPath = '';
- $scriptName = $_SERVER['SCRIPT_NAME'];
- if ('/' == substr($scriptName, -1)) {
- $scriptPath = $scriptName;
- } else {
- $scriptPathEx = explode('/', $scriptName);
- array_pop($scriptPathEx);
- $scriptPath = implode('/', $scriptPathEx) . '/';
- }
- $uri .= $scriptPath;
- return $uri;
- }
- // @usage: Request::getRewriteTaskPath();
- public static function getRewriteTaskPath() {
- $reqUri = $_SERVER['REQUEST_URI'];
- $reqScript = $_SERVER['SCRIPT_NAME'];
- $taskPath = str_replace($reqScript, '', $reqUri);
- return $taskPath;
- }
- // @usage: Request::getRequestBody();
- public static function getRequestBody() {
- static $requestBody = null;
- if (null === $requestBody) {
- $requestBody = file_get_contents("php://input");
- }
- return $requestBody;
- }
- }
|