152 'SERVER_NAME' =>
'localhost',
154 'HTTP_HOST' =>
'localhost',
155 'HTTP_USER_AGENT' =>
'Symfony/2.X',
156 'HTTP_ACCEPT' =>
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
157 'HTTP_ACCEPT_LANGUAGE' =>
'en-us,en;q=0.5',
158 'HTTP_ACCEPT_CHARSET' =>
'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
159 'REMOTE_ADDR' =>
'127.0.0.1',
161 'SCRIPT_FILENAME' =>
'',
162 'SERVER_PROTOCOL' =>
'HTTP/1.1',
163 'REQUEST_TIME' => time(),
169 $components = parse_url($uri);
170 if (isset($components[
'host'])) {
171 $server[
'SERVER_NAME'] = $components[
'host'];
172 $server[
'HTTP_HOST'] = $components[
'host'];
175 if (isset($components[
'scheme'])) {
176 if (
'https' === $components[
'scheme']) {
185 if (isset($components[
'port'])) {
186 $server[
'SERVER_PORT'] = $components[
'port'];
187 $server[
'HTTP_HOST'] =
$server[
'HTTP_HOST'] .
':' . $components[
'port'];
190 if (!isset($components[
'path'])) {
191 $components[
'path'] =
'/';
198 if (!isset(
$server[
'CONTENT_TYPE'])) {
199 $server[
'CONTENT_TYPE'] =
'application/x-www-form-urlencoded';
211 if (isset($components[
'query'])) {
212 parse_str(html_entity_decode($components[
'query']), $qs);
216 $queryString = http_build_query(
$query,
'',
'&');
218 $server[
'REQUEST_URI'] = $components[
'path'] . (
'' !== $queryString ?
'?' . $queryString :
'');
219 $server[
'QUERY_STRING'] = $queryString;
242 foreach (explode(
'&', $qs) as $param) {
243 if (
'' === $param ||
'=' === $param[0]) {
251 $keyValuePair = explode(
'=', $param, 2);
258 $parts[] = isset($keyValuePair[1]) ?
259 rawurlencode(urldecode($keyValuePair[0])) .
'=' . rawurlencode(urldecode($keyValuePair[1])) :
260 rawurlencode(urldecode($keyValuePair[0]));
261 $order[] = urldecode($keyValuePair[0]);
264 array_multisort($order, SORT_ASC, $parts);
266 return implode(
'&', $parts);
280 if ($this->query->has(
$key)) {
281 return $this->query->get(
$key);
282 }
else if ($this->request->has(
$key)) {
283 return $this->request->get(
$key);
295 if (
null === $this->requestUri) {
332 return $this->
isSecure() ?
'https' :
'http';
346 if ((
'http' == $scheme && $port == 80) || (
'https' == $scheme && $port == 443)) {
350 return $this->
getHost() .
':' . $port;
361 if (!$host = $this->headers->get(
'HOST')) {
362 if (!$host = $this->server->get(
'SERVER_NAME')) {
363 $host = $this->server->get(
'SERVER_ADDR',
'');
369 $host = strtolower(preg_replace(
'/:\d+$/',
'', trim($host)));
374 if ($host && !preg_match(
'/^\[?(?:[a-zA-Z0-9-:\]_]+\.?)+$/', $host)) {
375 throw new UnexpectedValueException(
'Invalid Host');
387 return 'on' == strtolower($this->server->get(
'HTTPS')) || 1 == $this->server->get(
'HTTPS');
396 return $this->server->get(
'SERVER_PORT');
413 if (
null === $this->baseUrl) {
436 if (
null === $this->pathInfo) {
454 return '' === $qs ? null : $qs;
465 $path = trim($this->query->get(
'__elgg_uri'),
'/');
470 return explode(
'/',
$path);
483 return array_shift($segments);
497 $ip_address =
$server->get(
'HTTP_X_FORWARDED_FOR');
498 if (!empty($ip_address)) {
499 return array_pop(explode(
',', $ip_address));
502 $ip_address =
$server->get(
'HTTP_X_REAL_IP');
503 if (!empty($ip_address)) {
504 return array_pop(explode(
',', $ip_address));
507 return $server->get(
'REMOTE_ADDR');
516 return $this->headers->get(
'X-Requested-With') ==
'XMLHttpRequest' ||
517 $this->
get(
'X-Requested-With') ===
'XMLHttpRequest';
527 if (get_magic_quotes_gpc()) {
541 $contentHeaders = array(
'CONTENT_LENGTH' =>
true,
'CONTENT_MD5' =>
true,
'CONTENT_TYPE' =>
true);
543 if (0 === strpos(
$key,
'HTTP_')) {
544 $key = strtr(strtolower(substr(
$key, 5)),
'_',
'-');
545 $key = implode(
'-', array_map(
'ucfirst', explode(
'-',
$key)));
547 } elseif (isset($contentHeaders[
$key])) {
548 $key = strtr(strtolower(
$key),
'_',
'-');
549 $key = implode(
'-', array_map(
'ucfirst', explode(
'-',
$key)));
566 return $this->server->get(
'REQUEST_URI');
575 $filename = basename($this->server->get(
'SCRIPT_FILENAME'));
577 if (basename($this->server->get(
'SCRIPT_NAME')) ===
$filename) {
578 $baseUrl = $this->server->get(
'SCRIPT_NAME');
579 } elseif (basename($this->server->get(
'PHP_SELF')) ===
$filename) {
580 $baseUrl = $this->server->get(
'PHP_SELF');
581 } elseif (basename($this->server->get(
'ORIG_SCRIPT_NAME')) ===
$filename) {
582 $baseUrl = $this->server->get(
'ORIG_SCRIPT_NAME');
586 $path = $this->server->get(
'PHP_SELF',
'');
587 $file = $this->server->get(
'SCRIPT_FILENAME',
'');
588 $segs = explode(
'/', trim($file,
'/'));
589 $segs = array_reverse($segs);
591 $last = count($segs);
594 $seg = $segs[$index];
597 }
while (($last > $index) && (
false !== ($pos = strpos(
$path,
$baseUrl))) && (0 != $pos));
610 return rtrim($prefix,
'/');
615 $truncatedRequestUri = substr(
$requestUri, 0, $pos);
619 if (empty($basename) || !strpos(rawurldecode($truncatedRequestUri), $basename)) {
672 private function getUrlencodedPrefix(
$string, $prefix) {
673 if (0 !== strpos(rawurldecode(
$string), $prefix)) {
677 $len = strlen($prefix);
679 if (preg_match(
"#^(%[[:xdigit:]]{2}|.){{$len}}#",
$string, $match)) {
getFirstUrlSegment()
Get first URL segment from the path info.
static createFromGlobals()
Creates a request from PHP's globals.
getPort()
Returns the port on which the request is made.
prepareBaseUrl()
Prepares the base URL.
static normalizeQueryString($qs)
Normalizes a query string.
prepareRequestUri()
Set the request URI.
getBaseUrl()
Returns the root url from which this request is executed.
preparePathInfo()
Prepares the path info.
static create($uri, $method='GET', $parameters=array(), $cookies=array(), $files=array(), $server=array())
Creates a Request based on a given URI and configuration.
prepareHeaders()
Get the HTTP headers from server.
getSchemeAndHttpHost()
Gets the scheme and HTTP host.
getScheme()
Gets the request's scheme.
getUrlSegments()
Get URL segments from the path info.
getHost()
Returns the host name.
initialize(array $query=array(), array $request=array(), array $cookies=array(), array $files=array(), array $server=array())
Initialize the request.
__construct(array $query=array(), array $request=array(), array $cookies=array(), array $files=array(), array $server=array())
Create a request.
getClientIp()
Get the IP address of the client.
getQueryString()
Gets the normalized query string for the Request.
getUri()
Generates a normalized URI for the Request.
isXmlHttpRequest()
Is this an ajax request.
getRequestUri()
Returns the requested URI.
getHttpHost()
Returns the HTTP host being requested.
getPathInfo()
Returns the path being requested relative to the executed script.
stripSlashesIfMagicQuotes($data)
Strip slashes if magic quotes is on.
isSecure()
Is this request using SSL.