Sections

Class Phalcon\Http\Request

implements Phalcon\Http\RequestInterface, Phalcon\Di\InjectionAwareInterface

Source on GitHub

Metody

Public

public function get( 
    [string $name = null 
    [, string | array $filters = null 
    [, mixed $defaultValue = null 
    [, bool $notAllowEmpty = false 
    [, bool $noRecursive = false ]]]]] 
): mixed

Gets a variable from the $_REQUEST superglobal applying filters if needed. If no parameters are given the $_REQUEST superglobal is returned

<?php

// Returns value from $_REQUEST["user_email"] without sanitizing
$userEmail = $request->get("user_email");

// Returns value from $_REQUEST["user_email"] with sanitizing
$userEmail = $request->get("user_email", "email");

public function getAcceptableContent(): array

Gets an array with mime/types and their quality accepted by the browser/client from $_SERVER["HTTP_ACCEPT"]


public function getBasicAuth(): array | null

Gets auth info accepted by the browser/client from $_SERVER["PHP_AUTH_USER"]


public function getBestAccept(): string

Gets best mime/type accepted by the browser/client from $_SERVER["HTTP_ACCEPT"]


public function getBestCharset(): string

Gets best charset accepted by the browser/client from $_SERVER["HTTP_ACCEPT_CHARSET"]


public function getBestLanguage(): string

Gets best language accepted by the browser/client from $_SERVER["HTTP_ACCEPT_LANGUAGE"]


public function getClientAddress( bool $trustForwardedHeader = false ): string | bool

Gets most possible client IPv4 Address. This method searches in $_SERVER["REMOTE_ADDR"] and optionally in $_SERVER["HTTP_X_FORWARDED_FOR"]


public function getClientCharsets(): array

Gets a charsets array and their quality accepted by the browser/client from $_SERVER["HTTP_ACCEPT_CHARSET"]


public function getContentType(): string | null

Gets content type which request has been made


public function getDigestAuth(): array

Gets auth info accepted by the browser/client from $_SERVER["PHP_AUTH_DIGEST"]


public function getDI(): Phalcon\Di\DiInterface

Returns the internal dependency injector

<hr/>
```php
public function getFilteredPost(
    [string $name = null 
    [, mixed $defaultValue = null 
    [, bool $notAllowEmpty = false 
    [, bool $noRecursive = false ]]]] 
): mixed

Retrieves a post value always sanitized with the preset filters


public function getFilteredPut(
    [string $name = null 
    [, mixed $defaultValue = null 
    [, bool $notAllowEmpty = false 
    [, bool $noRecursive = false ]]]] 
): mixed

Retrieves a put value always sanitized with the preset filters


public function getFilteredQuery(
    [string $name = null 
    [, mixed $defaultValue = null 
    [, bool $notAllowEmpty = false 
    [, bool $noRecursive = false ]]]] 
): mixed

Retrieves a query/get value always sanitized with the preset filters


public function getHeader( string $header ): string

Gets HTTP header from request data


public function getHeaders(): array

Returns the available headers in the request ```php <?php

$_SERVER = [ “PHP_AUTH_USER” => “phalcon”, “PHP_AUTH_PW” => “secret”, ];

$headers = $request->getHeaders();

echo $headers[“Authorization”]; // Basic cGhhbGNvbjpzZWNyZXQ=

<hr/>
```php
public function getHttpHost(): string

Gets the host name used by the request. The method will try to find host name in following order: - $_SERVER["HTTP_HOST"] - $_SERVER["SERVER_NAME"] - $_SERVER["SERVER_ADDR"]

Optionally getHttpHost() validates and performs a strict check on the host name. To achieve that you can use the setStrictHostCheck() method.

<?php

use Phalcon\Http\Request;

$request = new Request;

$_SERVER["HTTP_HOST"] = "example.com";
$request->getHttpHost(); // example.com

$_SERVER["HTTP_HOST"] = "example.com:8080";
$request->getHttpHost(); // example.com:8080

$request->setStrictHostCheck(true);
$_SERVER["HTTP_HOST"] = "ex=am~ple.com";
$request->getHttpHost(); // UnexpectedValueException

$_SERVER["HTTP_HOST"] = "ExAmPlE.com";
$request->getHttpHost(); // example.com

public function getHttpMethodParameterOverride(): bool

Returns the method parameter override setting


public function getHTTPReferer(): string

Gets the web page that was the original referrer for the request. ie: https://www.duckduckgo.com


public function getJsonRawBody( bool $associative = false ): \stdClass | array | bool

Gets the decoded JSON HTTP raw request body


public function getLanguages(): array

Gets a languages array and their quality accepted by the browser/client from $_SERVER["HTTP_ACCEPT_LANGUAGE"]


public function getMethod(): string

Gets HTTP method which request has been made. If the X-HTTP-Method-Override header is set, and if the method is a POST, then it is used to determine the “real” intended HTTP method. The _method request parameter can also be used to determine the HTTP method, setHttpMethodParameterOverride(true) has been called. The method always returns an uppercase string.


public function getPort(): int

Gets the port the request was made


public function getServer( string $name ): string | null

Gets server’s address IP


public function getServerAddress(): string

Gets the server’s IP address


public function setHttpMethodParameterOverride( bool $httpMethodParameterOverride )

Sets the method parameter override setting


public final function getURI(): string

Gets the HTTP URI of the request


public function getPost( 
    [string $name = null 
    [, string | array $filters = null 
    [, mixed $defaultValue = null 
    [, bool $notAllowEmpty = false 
    [, bool $noRecursive = false ]]]]] 
): mixed

Gets a variable from a POST request


public function getPut( 
    [string $name = null 
    [, string | array $filters = null 
    [, mixed $defaultValue = null 
    [, bool $notAllowEmpty = false 
    [, bool $noRecursive = false ]]]]] 
): mixed

Gets a variable from a PUT request


public function getQuery( 
    [string $name = null 
    [, string | array $filters = null 
    [, mixed $defaultValue = null 
    [, bool $notAllowEmpty = false 
    [, bool $noRecursive = false ]]]]] 
): mixed

Gets a variable from a GET request


public function getRawBody(): string

Gets the raw request body


public function getScheme(): string

Gets the HTTP schema (http/https)


public function getServer(string name): string | null

Gets an element from $_SERVER superglobal


public function getServerAddress(): string

Gets the active server address IP


public function getServerName(): string

Gets the active server name


public function getUploadedFiles(
    bool $onlySuccessful = false, 
    bool $namedKeys = false 
): Phalcon\Http\Request\FileInterface[]

Gets the attached files contained in a collection of Phalcon\Http\Request\FileInterface objects


public function getUserAgent(): string

Gets the user agent used for this request


public function has( string $name ): bool

Checks whether $_REQUEST superglobal has a certain element


public function hasFiles( bool $onlySuccessful = false ): long

Checks whether the request has attached files


public function hasHeader( string $header ): bool

Checks whether the headers have a certain element


public function hasPost( string $name ): bool

Checks whether $_POST superglobal has a certain element


public function hasPut( string name ): bool

Checks whether the PUT data has a certain element


public function hasQuery( string $name ): bool

Checks whether $_GET superglobal has a certain element


public function hasServer( string $name ): bool

Checks whether $_SERVER superglobal has a certain element


public function isAjax(): bool

Checks whether request was made using Ajax. ($_SERVER["HTTP_X_REQUESTED_WITH"] === "XMLHttpRequest")


public function isConnect(): bool

Checks whether HTTP method is CONNECT. ($_SERVER["REQUEST_METHOD"] === "CONNECT")


public function isDelete(): bool

Checks whether HTTP method is DELETE. ($_SERVER["REQUEST_METHOD"] === "DELETE")


public function isGet(): bool

Checks whether HTTP method is GET. ($_SERVER["REQUEST_METHOD"] === "GET")


public function isHead(): bool

Checks whether HTTP method is HEAD. ($_SERVER["REQUEST_METHOD"] === "HEAD")


public function isMethod( string | array $methods, bool $strict = false ): bool

Check if HTTP method match any of the passed methods


public function isOptions(): bool

Checks whether HTTP method is OPTIONS. ($_SERVER["REQUEST_METHOD"] === "OPTIONS")


public function isPost(): bool

Checks whether HTTP method is POST. ($_SERVER[“REQUEST_METHOD”] === “POST”`)


public function isPurge(): bool

Checks whether HTTP method is PURGE (Squid and Varnish support). ($_SERVER["REQUEST_METHOD"] === "PURGE")


public function isPut(): bool

Checks whether HTTP method is PUT. ($_SERVER["REQUEST_METHOD"] === "PUT")


public function isSecure(): bool

Checks whether request has been made using a secure layer


public function isSoap(): bool

Checks whether request has been made using SOAP


public function isTrace(): bool

Checks whether HTTP method is TRACE. ($_SERVER["REQUEST_METHOD"] === "TRACE")

<hr/>
```php
public function isValidHttpMethod( string $method ): bool

Checks if a method is a valid HTTP method

<hr/>
```php
public function setDI( Phacon\Di\DiInterface $container)

Sets the dependency injector


public function setParameterFilters( string $name, array $filters = [], array $scope = [] ): Phalcon\Http\RequestInterface

Sets automatic sanitizers/filters for a particular field and for particular methods

<hr/>
```php
public function setStrictHostCheck( bool $flag = true ): Phalcon\Http\RequestInterface

Sets if the Request::getHttpHost method must be use strict validation of host name or not


Protected

protected final function getHelper( 
    array $source, 
    string $name = null, 
    array | string $filters = null, 
    mixed $defaultValue = null, 
    bool $notAllowEmpty = false, 
    bool $noRecursive = false 
): mixed

Helper to get data from superglobals, applying filters if needed. If no parameters are given the superglobal is returned.


protected final function hasFileHelper( mixed $data, bool $onlySuccessful ): long

Recursively counts file in an array of files


protected final function getBestQuality( array $qualityParts, string $name ): string

Process a request header and return the one with best quality


protected final function getQualityHeader( string $serverIndex, string $name ): array

Process a request header and return an array of values with their qualities


protected function resolveAuthorizationHeaders(): array

Resolve authorization headers.


protected final function smoothFiles( 
    array $names, 
    array $types, 
    array $tmp_names, 
    array $sizes, 
    array $errors, 
    string $prefix 
): array

Smooth out $_FILES to have plain array with all files uploaded ```