HttpRequestVariable
- Type
- Class
- Namespace
- Craft
- Inherits
- Craft\HttpRequestVariable
- Since
- 1.0
Request functions.
See also http://craftcms.com
View source (opens new window)
# 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 {@link HttpCookie} 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.
View source (opens new window)
Returns
string (opens new window) – The OS the client is running.
Signature
public string getClientOs ( )
# getCookie()
Returns a {@link HttpCookie} if it exists, otherwise, null.
View source (opens new window)
Arguments
$name
Returns
Signature
public Craft\HttpCookie, null getCookie ( $name )
# 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.
View source (opens new window)
Returns
string (opens new window) – The random token for CSRF validation.
Signature
public string getCsrfToken ( )
# getFirstSegment()
Signature
public string, null getFirstSegment ( )
# 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.
View source (opens new window)
Arguments
$schema
(string (opens new window))
Returns
Signature
public string getHostInfo ( $schema = '' )
# 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.
View source (opens new window)
Returns
string (opens new window) – The IP address.
Signature
public string getIpAddress ( )
# getLastSegment()
Signature
public string, null getLastSegment ( )
# getPageNum()
Signature
public integer getPageNum ( )
# getParam()
Returns a variable from either the query string or the post data.
View source (opens new window)
Arguments
$name
(string (opens new window))$default
(string (opens new window), null (opens new window))
Returns
mixed
Signature
public mixed getParam ( $name, $default = null )
# getPath()
Signature
public mixed getPath ( )
# 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.
View source (opens new window)
Returns
Signature
public string getPathInfo ( )
# 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.
View source (opens new window)
Returns
Signature
public integer getPort ( )
# getPost()
Returns a value from post data.
View source (opens new window)
Arguments
$name
(string (opens new window), null (opens new window))$default
(string (opens new window), null (opens new window))
Returns
mixed
Signature
public mixed getPost ( $name = null, $default = null )
# getQuery()
Returns a variable from the query string.
View source (opens new window)
Arguments
$name
(string (opens new window), null (opens new window))$default
(string (opens new window), null (opens new window))
Returns
mixed
Signature
public mixed getQuery ( $name = null, $default = null )
# getQueryString()
Returns part of the request URL that is after the question mark.
View source (opens new window)
Returns
string (opens new window) – The part of the request URL that is after the question mark.
Signature
public string getQueryString ( )
# getQueryStringWithoutPath()
Returns the request’s query string, without the p= parameter.
View source (opens new window)
Returns
string (opens new window) – The query string.
Signature
public string getQueryStringWithoutPath ( )
# 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.
View source (opens new window)
Returns
Signature
public string getRequestUri ( )
# getScriptName()
Signature
public string getScriptName ( )
# getScriptUrl()
Signature
public string getScriptUrl ( )
# getSegment()
Returns a specific URI segment, or null if the segment doesn't exist.
View source (opens new window)
Arguments
$num
(integer (opens new window))
Returns
Signature
public string, null getSegment ( $num )
# getSegments()
Signature
public array getSegments ( )
# getServerName()
Signature
public string getServerName ( )
# getServerPort()
Signature
public integer getServerPort ( )
# getUrl()
Signature
public mixed getUrl ( )
# getUrlFormat()
Returns which URL format we're using (PATH_INFO or the query string)
View source (opens new window)
Returns
Signature
public string getUrlFormat ( )
# getUrlReferrer()
Signature
public string getUrlReferrer ( )
# getUserAgent()
Signature
public string getUserAgent ( )
# getUserHost()
Returns the user host name or null if it cannot be determined.
View source (opens new window)
Returns
Signature
public string getUserHost ( )
# getUserHostAddress()
Signature
public string getUserHostAddress ( )
# isAjax()
Signature
public boolean isAjax ( )
# isDelete()
Returns whether this is a DELETE request.
View source (opens new window)
Returns
boolean (opens new window) – Whether this is a DELETE request
Signature
public boolean isDelete ( )
# isGet()
Returns whether this is a GET request.
View source (opens new window)
Returns
boolean (opens new window) – Whether this is a GET request
Signature
public boolean isGet ( )
# isLivePreview()
Signature
public boolean isLivePreview ( )
# isMobileBrowser()
Returns whether the request is coming from a mobile browser.
View source (opens new window)
Arguments
$detectTablets
(boolean (opens new window))
Returns
Signature
public boolean isMobileBrowser ( $detectTablets = false )
# isPost()
Returns whether this is a POST request.
View source (opens new window)
Returns
boolean (opens new window) – Whether this is a POST request
Signature
public boolean isPost ( )
# isPut()
Returns whether this is a PUT request.
View source (opens new window)
Returns
boolean (opens new window) – Whether this is a PUT request
Signature
public boolean isPut ( )
# isSecure()
Signature
public boolean isSecure ( )