voku\helper\Bootup::filterRequestUri PHP Method

filterRequestUri() public static method

Filter current REQUEST_URI .
public static filterRequestUri ( string | null $uri = null, boolean $exit = true ) : mixed
$uri string | null

If null is set, then the server REQUEST_URI will be used.

$exit boolean
return mixed
    public static function filterRequestUri($uri = null, $exit = true)
    {
        if (!isset($uri)) {
            if (!isset($_SERVER['REQUEST_URI'])) {
                return false;
            } else {
                $uri = $_SERVER['REQUEST_URI'];
            }
        }
        $uriOrig = $uri;
        //
        // Ensures the URL is well formed UTF-8
        //
        if (preg_match('//u', urldecode($uri))) {
            return $uri;
        }
        //
        // When not, assumes Windows-1252 and redirects to the corresponding UTF-8 encoded URL
        //
        $uri = preg_replace_callback('/[\\x80-\\xFF]+/', function ($m) {
            return urlencode($m[0]);
        }, $uri);
        $uri = preg_replace_callback('/(?:%[89A-F][0-9A-F])+/i', function ($m) {
            return urlencode(UTF8::encode('UTF-8', urldecode($m[0])));
        }, $uri);
        if ($uri !== $uriOrig && $exit === true && headers_sent() === false) {
            // Use ob_start() to buffer content and avoid problem of headers already sent...
            $severProtocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
            header($severProtocol . ' 301 Moved Permanently');
            header('Location: ' . $uri);
            exit;
        }
        return $uri;
    }

Usage Example

Esempio n. 1
0
File: UTF8.php Progetto: hhgr/hhgolf
 /**
  * check for UTF8-Support
  */
 public static function checkForSupport()
 {
     if (!isset(self::$support['mbstring'])) {
         self::$support['mbstring'] = self::mbstring_loaded();
         self::$support['iconv'] = self::iconv_loaded();
         self::$support['intl'] = self::intl_loaded();
         self::$support['pcre_utf8'] = self::pcre_utf8_support();
         Bootup::initAll();
         // Enables the portablity layer and configures PHP for UTF-8
         Bootup::filterRequestUri();
         // Redirects to an UTF-8 encoded URL if it's not already the case
         Bootup::filterRequestInputs();
         // Normalizes HTTP inputs to UTF-8 NFC
     }
 }
All Usage Examples Of voku\helper\Bootup::filterRequestUri