Craft 3 Class Reference

Class craft\web\twig\variables\Request

Inheritance
craft\web\twig\variables\Request
Available since version
3.0
Deprecated since version
in 3.0
Source Code
https://github.com/craftcms/cms/blob/master/src/web/twig/variables/Request.php

Request functions.

Public Methods
Method Description Defined By
getClientOs() Returns whether the client is running "Windows", "Mac", "Linux" or "Other", based on the browser's UserAgent string. craft\web\twig\variables\Request
getCookie() Returns a yii\web\Cookie if it exists, otherwise, null. craft\web\twig\variables\Request
getCsrfToken() Returns the random token used to perform CSRF validation. craft\web\twig\variables\Request
getFirstSegment() Returns the first URI segment. craft\web\twig\variables\Request
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. craft\web\twig\variables\Request
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. craft\web\twig\variables\Request
getLastSegment() Returns the last URL segment. craft\web\twig\variables\Request
getPageNum() Returns the page number if this is a paginated request. craft\web\twig\variables\Request
getParam() Returns a variable from either the query string or the post data. craft\web\twig\variables\Request
getPath() Returns the request's URI. craft\web\twig\variables\Request
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. craft\web\twig\variables\Request
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. craft\web\twig\variables\Request
getPost() Returns a value from post data. craft\web\twig\variables\Request
getQuery() Returns a variable from the query string. craft\web\twig\variables\Request
getQueryString() Returns part of the request URL that is after the question mark. craft\web\twig\variables\Request
getQueryStringWithoutPath() Returns the request’s query string, without the p= parameter. craft\web\twig\variables\Request
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. craft\web\twig\variables\Request
getScriptName() Returns the script name used to access Craft. craft\web\twig\variables\Request
getScriptUrl() Returns the relative URL of the entry script. craft\web\twig\variables\Request
getSegment() Returns a specific URI segment, or null if the segment doesn't exist. craft\web\twig\variables\Request
getSegments() Returns all URI segments. craft\web\twig\variables\Request
getServerName() Returns the server name. craft\web\twig\variables\Request
getServerPort() Returns the server port number. craft\web\twig\variables\Request
getUrl() Returns the request's full URL. craft\web\twig\variables\Request
getUrlFormat() Returns which URL format we're using (PATH_INFO or the query string) craft\web\twig\variables\Request
getUrlReferrer() Returns the URL referrer or null if not present. craft\web\twig\variables\Request
getUserAgent() Returns the user agent or null if not present. craft\web\twig\variables\Request
getUserHost() Returns the user host name or null if it cannot be determined. craft\web\twig\variables\Request
getUserHostAddress() Returns the user IP address. craft\web\twig\variables\Request
isAjax() Returns whether this is an Ajax request. craft\web\twig\variables\Request
isDelete() Returns whether this is a DELETE request. craft\web\twig\variables\Request
isGet() Returns whether this is a GET request. craft\web\twig\variables\Request
isLivePreview() Returns whether this is a Live Preview request. craft\web\twig\variables\Request
isMobileBrowser() Returns whether the request is coming from a mobile browser. craft\web\twig\variables\Request
isPost() Returns whether this is a POST request. craft\web\twig\variables\Request
isPut() Returns whether this is a PUT request. craft\web\twig\variables\Request
isSecure() Returns whether this is a secure connection. craft\web\twig\variables\Request

Method Details

getClientOs() public method #

Returns whether the client is running "Windows", "Mac", "Linux" or "Other", based on the browser's UserAgent string.

public string getClientOs ( )
return string The OS the client is running.

getCookie() public method #

Returns a yii\web\Cookie if it exists, otherwise, null.

public yii\web\Cookie, null getCookie ( \craft\web\twig\variables\string $name )
$name string

getCsrfToken() public method #

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.

public string getCsrfToken ( )
return string The random token for CSRF validation.

getFirstSegment() public method #

Returns the first URI segment.

public string, null getFirstSegment ( )

getHostInfo() public method #

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.

public string getHostInfo ( )

getIpAddress() public method #

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.

public string getIpAddress ( )
return string The IP address.

getLastSegment() public method #

Returns the last URL segment.

public string, null getLastSegment ( )

getPageNum() public method #

Returns the page number if this is a paginated request.

public integer getPageNum ( )

getParam() public method #

Returns a variable from either the query string or the post data.

public mixed getParam ( \craft\web\twig\variables\string $name, \craft\web\twig\variables\string $default null )
$name string
$default string, null

getPath() public method #

Returns the request's URI.

public mixed getPath ( )

getPathInfo() public method #

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.

public string getPathInfo ( )

getPort() public method #

Returns the port to use for insecure requests. Defaults to 80, or the port specified by the server if the current request is insecure.

public integer getPort ( )

getPost() public method #

Returns a value from post data.

public mixed getPost ( \craft\web\twig\variables\string $name null, \craft\web\twig\variables\string $default null )
$name string, null
$default string, null

getQuery() public method #

Returns a variable from the query string.

public mixed getQuery ( \craft\web\twig\variables\string $name null, \craft\web\twig\variables\string $default null )
$name string, null
$default string, null

getQueryString() public method #

Returns part of the request URL that is after the question mark.

public string getQueryString ( )
return string The part of the request URL that is after the question mark.

getQueryStringWithoutPath() public method #

Returns the request’s query string, without the p= parameter.

public string getQueryStringWithoutPath ( )
return string The query string.

getRequestUri() public method #

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.

public string getRequestUri ( )

getScriptName() public method #

Returns the script name used to access Craft.

public string getScriptName ( )

getScriptUrl() public method #

Returns the relative URL of the entry script.

public string getScriptUrl ( )

getSegment() public method #

Returns a specific URI segment, or null if the segment doesn't exist.

public string, null getSegment ( \craft\web\twig\variables\int $num )
$num integer

getSegments() public method #

Returns all URI segments.

public array getSegments ( )

getServerName() public method #

Returns the server name.

public string getServerName ( )

getServerPort() public method #

Returns the server port number.

public integer, null getServerPort ( )

getUrl() public method #

Returns the request's full URL.

public mixed getUrl ( )

getUrlFormat() public method #

Returns which URL format we're using (PATH_INFO or the query string)

public string getUrlFormat ( )

getUrlReferrer() public method #

Returns the URL referrer or null if not present.

public string getUrlReferrer ( )

getUserAgent() public method #

Returns the user agent or null if not present.

public string getUserAgent ( )

getUserHost() public method #

Returns the user host name or null if it cannot be determined.

public string, null getUserHost ( )

getUserHostAddress() public method #

Returns the user IP address.

public string getUserHostAddress ( )

isAjax() public method #

Returns whether this is an Ajax request.

public boolean isAjax ( )

isDelete() public method #

Returns whether this is a DELETE request.

public boolean isDelete ( )
return boolean Whether this is a DELETE request

isGet() public method #

Returns whether this is a GET request.

public boolean isGet ( )
return boolean Whether this is a GET request

isLivePreview() public method #

Returns whether this is a Live Preview request.

public boolean isLivePreview ( )

isMobileBrowser() public method #

Returns whether the request is coming from a mobile browser.

public boolean isMobileBrowser ( \craft\web\twig\variables\bool $detectTablets false )
$detectTablets boolean

isPost() public method #

Returns whether this is a POST request.

public boolean isPost ( )
return boolean Whether this is a POST request

isPut() public method #

Returns whether this is a PUT request.

public boolean isPut ( )
return boolean Whether this is a PUT request

isSecure() public method #

Returns whether this is a secure connection.

public boolean isSecure ( )