daux.io/libs/Server/Helper.php

39 lines
1.3 KiB
PHP
Raw Normal View History

2015-04-22 12:23:57 +02:00
<?php namespace Todaymade\Daux\Server;
2015-04-23 00:32:30 +02:00
class Helper
{
public static function getRequest()
2015-04-22 12:23:57 +02:00
{
2015-04-23 00:32:30 +02:00
if (isset($_SERVER['PATH_INFO'])) {
$uri = $_SERVER['PATH_INFO'];
} elseif (isset($_SERVER['REQUEST_URI'])) {
2015-04-22 12:23:57 +02:00
$uri = $_SERVER['REQUEST_URI'];
2015-04-23 00:32:30 +02:00
if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0) {
$uri = substr($uri, strlen($_SERVER['SCRIPT_NAME']));
} elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0) {
$uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME'])));
}
if (strncmp($uri, '?/', 2) === 0) {
$uri = substr($uri, 2);
}
2015-04-22 12:23:57 +02:00
$parts = preg_split('#\?#i', $uri, 2);
$uri = $parts[0];
if (isset($parts[1])) {
$_SERVER['QUERY_STRING'] = $parts[1];
parse_str($_SERVER['QUERY_STRING'], $_GET);
} else {
$_SERVER['QUERY_STRING'] = '';
$_GET = array();
}
$uri = parse_url($uri, PHP_URL_PATH);
2015-04-23 00:32:30 +02:00
} else {
return false;
2015-04-22 12:23:57 +02:00
}
$uri = str_replace(array('//', '../'), '/', trim($uri, '/'));
2015-04-23 00:32:30 +02:00
if ($uri == "") {
$uri = "first_page";
}
2015-04-22 12:23:57 +02:00
return $uri;
}
}