implements Phalcon\Http\RequestInterface, Phalcon\Di\InjectionAwareInterface
Encapsulates request information for easy and secure access from application controllers.
The request object is a simple value object that is passed between the dispatcher and controller classes. It packages the HTTP request environment.
use Phalcon\Http\Request; $request = new Request(); if ($request->isPost() && $request->isAjax()) { echo "Request was made using POST and AJAX"; } $request->getServer("HTTP_HOST"); // Retrieve SERVER variables $request->getMethod(); // GET, POST, PUT, DELETE, HEAD, OPTIONS, PATCH, PURGE, TRACE, CONNECT $request->getLanguages(); // An array of languages the client accepts
...
...
Sets the dependency injector
Returns the internal dependency injector
Gets a variable from the $_REQUEST superglobal applying filters if needed. If no parameters are given the $_REQUEST superglobal is returned
// 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");
Gets a variable from the $_POST superglobal applying filters if needed If no parameters are given the $_POST superglobal is returned
// Returns value from $_POST["user_email"] without sanitizing $userEmail = $request->getPost("user_email"); // Returns value from $_POST["user_email"] with sanitizing $userEmail = $request->getPost("user_email", "email");
Gets a variable from put request
// Returns value from $_PUT["user_email"] without sanitizing $userEmail = $request->getPut("user_email"); // Returns value from $_PUT["user_email"] with sanitizing $userEmail = $request->getPut("user_email", "email");
Gets variable from $_GET superglobal applying filters if needed If no parameters are given the $_GET superglobal is returned
// Returns value from $_GET["id"] without sanitizing $id = $request->getQuery("id"); // Returns value from $_GET["id"] with sanitizing $id = $request->getQuery("id", "int"); // Returns value from $_GET["id"] with a default value $id = $request->getQuery("id", null, 150);
Helper to get data from superglobals, applying filters if needed. If no parameters are given the superglobal is returned.
Gets variable from $_SERVER superglobal
Checks whether $_REQUEST superglobal has certain index
Checks whether $_POST superglobal has certain index
Checks whether the PUT data has certain index
Checks whether $_GET superglobal has certain index
Checks whether $_SERVER superglobal has certain index
Gets HTTP header from request data
Gets HTTP schema (http/https)
Checks whether request has been made using ajax
Checks whether request has been made using SOAP
Alias of isSoap(). It will be deprecated in future versions
Checks whether request has been made using any secure layer
Alias of isSecure(). It will be deprecated in future versions
Gets HTTP raw request body
Gets decoded JSON HTTP raw request body
Gets active server address IP
Gets active server name
Gets host name used by the request. Request::getHttpHost trying to find host name in following order: - $_SERVER[“HTTP_HOST”] - $_SERVER[“SERVER_NAME”] - $_SERVER[“SERVER_ADDR”] Optionally Request::getHttpHost validates and clean host name. The Request::$_strictHostCheck can be used to validate host name. Note: validation and cleaning have a negative performance impact because they use regular expressions.
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
Sets if the Request::getHttpHost method must be use strict validation of host name or not
Checks if the Request::getHttpHost method will be use strict validation of host name or not
Gets information about the port on which the request is made.
Gets HTTP URI which request has been made
Gets most possible client IPv4 Address. This method searches in $_SERVER[“REMOTE_ADDR”] and optionally in $_SERVER[“HTTP_X_FORWARDED_FOR”]
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, but only if setHttpMethodParameterOverride(true) has been called. The method is always an uppercased string.
Gets HTTP user agent used to made the request
Checks if a method is a valid HTTP method
Check if HTTP method match any of the passed methods When strict is true it checks if validated methods are real HTTP methods
Checks whether HTTP method is POST. if _SERVER[“REQUEST_METHOD”]===”POST”
Checks whether HTTP method is GET. if _SERVER[“REQUEST_METHOD”]===”GET”
Checks whether HTTP method is PUT. if _SERVER[“REQUEST_METHOD”]===”PUT”
Checks whether HTTP method is PATCH. if _SERVER[“REQUEST_METHOD”]===”PATCH”
Checks whether HTTP method is HEAD. if _SERVER[“REQUEST_METHOD”]===”HEAD”
Checks whether HTTP method is DELETE. if _SERVER[“REQUEST_METHOD”]===”DELETE”
Checks whether HTTP method is OPTIONS. if _SERVER[“REQUEST_METHOD”]===”OPTIONS”
Checks whether HTTP method is PURGE (Squid and Varnish support). if _SERVER[“REQUEST_METHOD”]===”PURGE”
Checks whether HTTP method is TRACE. if _SERVER[“REQUEST_METHOD”]===”TRACE”
Checks whether HTTP method is CONNECT. if _SERVER[“REQUEST_METHOD”]===”CONNECT”
Checks whether request include attached files
Recursively counts file in an array of files
Gets attached files as Phalcon\Http\Request\File instances
Smooth out $_FILES to have plain array with all files uploaded
Returns the available headers in the request
$_SERVER = [ "PHP_AUTH_USER" => "phalcon", "PHP_AUTH_PW" => "secret", ]; $headers = $request->getHeaders(); echo $headers["Authorization"]; // Basic cGhhbGNvbjpzZWNyZXQ=
Gets web page that refers active request. ie: http://www.google.com
Process a request header and return the one with best quality
Gets content type which request has been made
Gets an array with mime/types and their quality accepted by the browser/client from _SERVER[“HTTP_ACCEPT”]
Gets best mime/type accepted by the browser/client from _SERVER[“HTTP_ACCEPT”]
Gets a charsets array and their quality accepted by the browser/client from _SERVER[“HTTP_ACCEPT_CHARSET”]
Gets best charset accepted by the browser/client from _SERVER[“HTTP_ACCEPT_CHARSET”]
Gets languages array and their quality accepted by the browser/client from _SERVER[“HTTP_ACCEPT_LANGUAGE”]
Gets best language accepted by the browser/client from _SERVER[“HTTP_ACCEPT_LANGUAGE”]
Gets auth info accepted by the browser/client from $_SERVER[“PHP_AUTH_USER”]
Gets auth info accepted by the browser/client from $_SERVER[“PHP_AUTH_DIGEST”]
Process a request header and return an array of values with their qualities
© 2011–2017 Phalcon Framework Team
Licensed under the Creative Commons Attribution License 3.0.
https://docs.phalconphp.com/en/latest/api/Phalcon_Http_Request.html