Request ​
- Type
- Class
- Namespace
- craft\web\twig\variables
- Inherits
- craft\web\twig\variables\Request
- Since
- 3.0.0
- Deprecated in
- in 3.0.0
Request functions.
Public Methods ​
Method | Description |
---|---|
getClientOs() | Returns whether the client is running "Windows", "Mac", "Linux" or "Other", based on the browser's UserAgent string. |
getCookie() | Returns a yii\web\Cookie if it exists, otherwise, null. |
getCsrfToken() | Returns the random token used to perform CSRF validation. |
getFirstSegment() | Returns the first URI segment. |
getHostInfo() | Returns the schema and host part of the application URL. The returned URL does not have an ending slash. By default this is determined based on the user request information. |
getIpAddress() | Retrieves the best guess of the client’s actual IP address taking into account numerous HTTP proxy headers due to variations in how different ISPs handle IP addresses in headers between hops. |
getLastSegment() | Returns the last URL segment. |
getPageNum() | Returns the page number if this is a paginated request. |
getParam() | Returns a variable from either the query string or the post data. |
getPath() | Returns the request's URI. |
getPathInfo() | Returns the path info of the currently requested URL. This refers to the part that is after the entry script and before the question mark. The starting and ending slashes are stripped off. |
getPort() | Returns the port to use for insecure requests. Defaults to 80, or the port specified by the server if the current request is insecure. |
getPost() | Returns a value from post data. |
getQuery() | Returns a variable from the query string. |
getQueryString() | Returns part of the request URL that is after the question mark. |
getQueryStringWithoutPath() | Returns the request’s query string, without the p= parameter. |
getRequestUri() | Returns the request URI portion for the currently requested URL. This refers to the portion that is after the host info part. It includes the query string part if any. |
getScriptName() | Returns the script name used to access Craft. |
getScriptUrl() | Returns the relative URL of the entry script. |
getSegment() | Returns a specific URI segment, or null if the segment doesn't exist. |
getSegments() | Returns all URI segments. |
getServerName() | Returns the server name. |
getServerPort() | Returns the server port number. |
getUrl() | Returns the request's full URL. |
getUrlFormat() | Returns which URL format we're using (PATH_INFO or the query string) |
getUrlReferrer() | Returns the URL referrer or null if not present. |
getUserAgent() | Returns the user agent or null if not present. |
getUserHost() | Returns the user host name or null if it cannot be determined. |
getUserHostAddress() | Returns the user IP address. |
isAjax() | Returns whether this is an Ajax request. |
isDelete() | Returns whether this is a DELETE request. |
isGet() | Returns whether this is a GET request. |
isLivePreview() | Returns whether this is a Live Preview request. |
isMobileBrowser() | Returns whether the request is coming from a mobile browser. |
isPost() | Returns whether this is a POST request. |
isPut() | Returns whether this is a PUT request. |
isSecure() | Returns whether this is a secure connection. |
getClientOs()
​
Returns whether the client is running "Windows", "Mac", "Linux" or "Other", based on the browser's UserAgent string.
Returns ​
string – The OS the client is running.
getCookie()
​
Returns a yii\web\Cookie if it exists, otherwise, null.
Arguments ​
$name
(string)
Returns ​
getCsrfToken()
​
Returns the random token used to perform CSRF validation.
The token will be read from cookie first. If not found, a new token will be generated.
Returns ​
string – The random token for CSRF validation.
getFirstSegment()
​
Returns the first URI segment.
Returns ​
getHostInfo()
​
Returns the schema and host part of the application URL. The returned URL does not have an ending slash. By default this is determined based on the user request information.
Returns ​
getIpAddress()
​
Retrieves the best guess of the client’s actual IP address taking into account numerous HTTP proxy headers due to variations in how different ISPs handle IP addresses in headers between hops.
Considering any of these server vars besides REMOTE_ADDR can be spoofed, this method should not be used when you need a trusted source for the IP address. Use $_SERVER['REMOTE_ADDR']
instead.
Returns ​
string, null – The IP address.
getLastSegment()
​
Returns the last URL segment.
Returns ​
getPageNum()
​
Returns the page number if this is a paginated request.
Returns ​
getParam()
​
Returns a variable from either the query string or the post data.
Arguments ​
Returns ​
mixed
getPath()
​
Returns the request's URI.
Returns ​
getPathInfo()
​
Returns the path info of the currently requested URL. This refers to the part that is after the entry script and before the question mark. The starting and ending slashes are stripped off.
Returns ​
getPort()
​
Returns the port to use for insecure requests. Defaults to 80, or the port specified by the server if the current request is insecure.
Returns ​
getPost()
​
Returns a value from post data.
Arguments ​
Returns ​
mixed
getQuery()
​
Returns a variable from the query string.
Arguments ​
Returns ​
mixed
getQueryString()
​
Returns part of the request URL that is after the question mark.
Returns ​
string – The part of the request URL that is after the question mark.
getQueryStringWithoutPath()
​
Returns the request’s query string, without the p= parameter.
Returns ​
string – The query string.
getRequestUri()
​
Returns the request URI portion for the currently requested URL. This refers to the portion that is after the host info part. It includes the query string part if any.
Returns ​
getScriptName()
​
Returns the script name used to access Craft.
Returns ​
getScriptUrl()
​
Returns the relative URL of the entry script.
Returns ​
getSegment()
​
Returns a specific URI segment, or null if the segment doesn't exist.
Arguments ​
$num
(integer)
Returns ​
getSegments()
​
Returns all URI segments.
Returns ​
getServerName()
​
Returns the server name.
Returns ​
getServerPort()
​
Returns the server port number.
Returns ​
getUrl()
​
Returns the request's full URL.
Returns ​
getUrlFormat()
​
Returns which URL format we're using (PATH_INFO or the query string)
Returns ​
getUrlReferrer()
​
Returns the URL referrer or null if not present.
Returns ​
getUserAgent()
​
Returns the user agent or null if not present.
Returns ​
getUserHost()
​
Returns the user host name or null if it cannot be determined.
Returns ​
getUserHostAddress()
​
Returns the user IP address.
Returns ​
isAjax()
​
Returns whether this is an Ajax request.
Returns ​
isDelete()
​
Returns whether this is a DELETE request.
Returns ​
boolean – Whether this is a DELETE request
isGet()
​
Returns whether this is a GET request.
Returns ​
boolean – Whether this is a GET request
isLivePreview()
​
Returns whether this is a Live Preview request.
Returns ​
isMobileBrowser()
​
Returns whether the request is coming from a mobile browser.
Arguments ​
$detectTablets
(boolean)
Returns ​
isPost()
​
Returns whether this is a POST request.
Returns ​
boolean – Whether this is a POST request
isPut()
​
Returns whether this is a PUT request.
Returns ​
boolean – Whether this is a PUT request
isSecure()
​
Returns whether this is a secure connection.