HEADER_CLIENT_IP
HEADER_CLIENT_IP
Request represents an HTTP request from an Apache server.
The methods dealing with URL accept / return a raw path (% encoded):
$attributes : \Symfony\Component\HttpFoundation\ParameterBag
$request : \Symfony\Component\HttpFoundation\ParameterBag
$query : \Symfony\Component\HttpFoundation\ParameterBag
$server : \Symfony\Component\HttpFoundation\ServerBag
$files : \Symfony\Component\HttpFoundation\FileBag
$cookies : \Symfony\Component\HttpFoundation\ParameterBag
$headers : \Symfony\Component\HttpFoundation\HeaderBag
$session : \Symfony\Component\HttpFoundation\Session\SessionInterface
__construct(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), string $content = null)
Constructor.
array | $query |
The GET parameters |
array | $request |
The POST parameters |
array | $attributes |
The request attributes (parameters parsed from the PATH_INFO, ...) |
array | $cookies |
The COOKIE parameters |
array | $files |
The FILES parameters |
array | $server |
The SERVER parameters |
string | $content |
The raw body data |
initialize(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), string $content = null)
Sets the parameters for this request.
This method also re-initializes all properties.
array | $query |
The GET parameters |
array | $request |
The POST parameters |
array | $attributes |
The request attributes (parameters parsed from the PATH_INFO, ...) |
array | $cookies |
The COOKIE parameters |
array | $files |
The FILES parameters |
array | $server |
The SERVER parameters |
string | $content |
The raw body data |
createFromGlobals() : \Symfony\Component\HttpFoundation\Request
Creates a new request with values from PHP's super globals.
A new request
create(string $uri, string $method = 'GET', array $parameters = array(), array $cookies = array(), array $files = array(), array $server = array(), string $content = null) : \Symfony\Component\HttpFoundation\Request
Creates a Request based on a given URI and configuration.
The information contained in the URI always take precedence over the other information (server and parameters).
string | $uri |
The URI |
string | $method |
The HTTP method |
array | $parameters |
The query (GET) or request (POST) parameters |
array | $cookies |
The request cookies ($_COOKIE) |
array | $files |
The request files ($_FILES) |
array | $server |
The server parameters ($_SERVER) |
string | $content |
The raw body data |
A Request instance
duplicate(array $query = null, array $request = null, array $attributes = null, array $cookies = null, array $files = null, array $server = null) : \Symfony\Component\HttpFoundation\Request
Clones a request and overrides some of its parameters.
array | $query |
The GET parameters |
array | $request |
The POST parameters |
array | $attributes |
The request attributes (parameters parsed from the PATH_INFO, ...) |
array | $cookies |
The COOKIE parameters |
array | $files |
The FILES parameters |
array | $server |
The SERVER parameters |
The duplicated request
setTrustedHeaderName(string $key, string $value)
Sets the name for trusted headers.
The following header keys are supported:
Setting an empty value allows to disable the trusted header for the given key.
string | $key |
The header key |
string | $value |
The header name |
normalizeQueryString(string $qs) : string
Normalizes a query string.
It builds a normalized query string, where keys/value pairs are alphabetized, have consistent escaping and unneeded delimiters are removed.
string | $qs |
Query string |
A normalized query string for the Request
enableHttpMethodParameterOverride()
Enables support for the _method request parameter to determine the intended HTTP method.
Be warned that enabling this feature might lead to CSRF issues in your code. Check that you are using CSRF tokens when required.
The HTTP method can only be overridden when the real HTTP method is POST.
get(string $key, mixed $default = null, Boolean $deep = false) : mixed
Gets a "parameter" value.
This method is mainly useful for libraries that want to provide some flexibility.
Order of precedence: GET, PATH, POST
Avoid using this method in controllers:
It is better to explicitly get request parameters from the appropriate public property instead (query, attributes, request).
string | $key |
the key |
mixed | $default |
the default value |
Boolean | $deep |
is parameter deep in multidimensional array |
getSession() : \Symfony\Component\HttpFoundation\Session\SessionInterface|null
Gets the Session.
The session
hasSession() : Boolean
Whether the request contains a Session object.
This method does not give any information about the state of the session object, like whether the session is started or not. It is just a way to check if this Request is associated with a Session instance.
true when the Request contains a Session object, false otherwise
setSession(\Symfony\Component\HttpFoundation\Session\SessionInterface $session)
Sets the Session.
SymfonyComponentHttpFoundationSessionSessionInterface | $session |
The Session |
getClientIp() : string
Returns the client IP address.
This method can read the client IP address from the "X-Forwarded-For" header when trusted proxies were set via "setTrustedProxies()". The "X-Forwarded-For" header value is a comma space separated list of IP addresses, the left-most being the original client, and each successive proxy that passed the request adding the IP address where it received the request from.
If your reverse proxy uses a different header name than "X-Forwarded-For", ("Client-Ip" for instance), configure it via "setTrustedHeaderName()" with the "client-ip" key.
The client IP address
getPathInfo() : string
Returns the path being requested relative to the executed script.
The path info always starts with a /.
Suppose this request is instantiated from /mysite on localhost:
The raw path (i.e. not urldecoded)
getBasePath() : string
Returns the root path from which this request is executed.
Suppose that an index.php file instantiates this request object:
The raw path (i.e. not urldecoded)
getPort() : string
Returns the port on which the request is made.
This method can read the client port from the "X-Forwarded-Port" header when trusted proxies were set via "setTrustedProxies()".
The "X-Forwarded-Port" header must contain the client port.
If your reverse proxy uses a different header name than "X-Forwarded-Port", configure it via "setTrustedHeaderName()" with the "client-port" key.
isSecure() : Boolean
Checks whether the request is secure or not.
This method can read the client port from the "X-Forwarded-Proto" header when trusted proxies were set via "setTrustedProxies()".
The "X-Forwarded-Proto" header must contain the protocol: "https" or "http".
If your reverse proxy uses a different header name than "X-Forwarded-Proto" ("SSL_HTTPS" for instance), configure it via "setTrustedHeaderName()" with the "client-proto" key.
getHost() : string
Returns the host name.
This method can read the client port from the "X-Forwarded-Host" header when trusted proxies were set via "setTrustedProxies()".
The "X-Forwarded-Host" header must contain the client host name.
If your reverse proxy uses a different header name than "X-Forwarded-Host", configure it via "setTrustedHeaderName()" with the "client-host" key.
when the host name is invalid
getMethod() : string
Gets the request "intended" method.
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 enableHttpMethodParameterOverride() has been called.
The method is always an uppercased string.
The request method
getRequestFormat(string $default = 'html') : string
Gets the request format.
Here is the process to determine the format:
string | $default |
The default format |
The request format
isXmlHttpRequest() : Boolean
Returns true if the request is a XMLHttpRequest.
It works if your JavaScript library set an X-Requested-With HTTP header. It is known to work with common JavaScript frameworks:
true if the request is an XMLHttpRequest, false otherwise
Documentation created by phpDocumentor