123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?php namespace System;
- class Request {
-
- public static $uri;
-
- public static function uri()
- {
-
-
-
- if ( ! is_null(static::$uri))
- {
- return static::$uri;
- }
-
-
-
- if (isset($_SERVER['PATH_INFO']))
- {
- $uri = $_SERVER['PATH_INFO'];
- }
-
-
-
- elseif (isset($_SERVER['REQUEST_URI']))
- {
- $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
- if ($uri === false)
- {
- throw new \Exception("Malformed request URI. Request terminated.");
- }
- }
-
-
-
- else
- {
- throw new \Exception('Unable to determine the request URI.');
- }
- $uri = trim($uri, '/');
-
-
-
-
- return static::$uri = ($uri == '') ? '/' : Str::lower($uri);
- }
-
- public static function method()
- {
-
-
-
-
- return (isset($_POST['request_method'])) ? $_POST['request_method'] : $_SERVER['REQUEST_METHOD'];
- }
-
- public static function ip()
- {
- if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
- {
- return $_SERVER['HTTP_X_FORWARDED_FOR'];
- }
- elseif (isset($_SERVER['HTTP_CLIENT_IP']))
- {
- return $_SERVER['HTTP_CLIENT_IP'];
- }
- elseif (isset($_SERVER['REMOTE_ADDR']))
- {
- return $_SERVER['REMOTE_ADDR'];
- }
- }
-
- public static function is_secure()
- {
- return (static::protocol() == 'https');
- }
-
- public static function protocol()
- {
- return (isset($_SERVER['HTTPS']) and $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
- }
-
- public static function is_ajax()
- {
- return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) and Str::lower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest');
- }
- }
|