Class CHttpRequest
CHttpRequest encapsulates the $_SERVER variable and resolves its inconsistency among different Web servers.
CHttpRequest also manages the cookies sent from and sent to the user. By
setting CHttpRequest::$enableCookieValidation
to true, cookies sent from the user will
be validated to see if they are tampered. The property getCookies
cookies returns the collection of cookies. For more details, see CCookieCollection
.
CHttpRequest is a default application component loaded by CWebApplication
. It can be accessed via CApplication::getRequest()
.
- CComponent
- CApplicationComponent implements IApplicationComponent
- CHttpRequest
Direct known subclasses
X2HttpRequestCopyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 1.0
Located at x2engine/framework/web/CHttpRequest.php
public
|
|
protected
|
#
normalizeRequest( )
Normalizes the request data. This method strips off slashes in request data
if get_magic_quotes_gpc() returns true. It also performs CSRF validation if
|
public
mixed
|
#
stripSlashes( mixed & $data )
Strips slashes from input data. This method is applied when magic quotes is enabled. |
public
mixed
|
|
public
mixed
|
|
public
mixed
|
|
public
mixed
|
#
getDelete( string $name, mixed $defaultValue = null )
Returns the named DELETE parameter value. If the DELETE parameter does not exist or if the current request is not a DELETE request, the second parameter to this method will be returned. If the DELETE request was tunneled through POST via _method parameter, the POST parameter will be returned instead (available since version 1.1.11). |
public
mixed
|
#
getPut( string $name, mixed $defaultValue = null )
Returns the named PUT parameter value. If the PUT parameter does not exist or if the current request is not a PUT request, the second parameter to this method will be returned. If the PUT request was tunneled through POST via _method parameter, the POST parameter will be returned instead (available since version 1.1.11). |
public
mixed
|
#
getPatch( string $name, mixed $defaultValue = null )
Returns the named PATCH parameter value. If the PATCH parameter does not exist or if the current request is not a PATCH request, the second parameter to this method will be returned. If the PATCH request was tunneled through POST via _method parameter, the POST parameter will be returned instead. |
public
array
|
|
public
string
|
|
public
string
|
|
public
string
|
#
getHostInfo( string $schema = '' )
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. You may explicitly specify it by setting the setHostInfo hostInfo property. |
public
|
#
setHostInfo( string $value )
Sets the schema and host part of the application URL. This setter is provided in case the schema and hostname cannot be determined on certain Web servers. |
public
string
|
#
getBaseUrl( boolean $absolute = false )
Returns the relative URL for the application. This is similar to getScriptUrl scriptUrl except that it does not have the script file name, and the ending slashes are stripped off. |
public
|
#
setBaseUrl( string $value )
Sets the relative URL for the application. By default the URL is determined based on the entry script URL. This setter is provided in case you want to change this behavior. |
public
string
|
#
getScriptUrl( )
Returns the relative URL of the entry script. The implementation of this method referenced Zend_Controller_Request_Http in Zend Framework. |
public
|
#
setScriptUrl( string $value )
Sets the relative URL for the application entry script. This setter is provided in case the entry script URL cannot be determined on certain Web servers. |
public
string
|
#
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. |
protected
string
|
#
decodePathInfo( string $pathInfo )
Decodes the path info. This method is an improved variant of the native urldecode() function and used in getPathInfo getPathInfo() to decode the path part of the request URI. You may override this method to change the way the path info is being decoded. |
public
string
|
#
getRequestUri( )
Returns the request URI portion for the currently requested URL. This refers to the portion that is after the hostInfo host info part. It includes the queryString query string part if any. The implementation of this method referenced Zend_Controller_Request_Http in Zend Framework. |
public
string
|
|
public
boolean
|
|
public
string
|
#
getRequestType( )
Returns the request type, such as GET, POST, HEAD, PUT, PATCH, DELETE. Request type can be manually set in POST requests with a parameter named _method. Useful for RESTful request from older browsers which do not support PUT, PATCH or DELETE natively (available since version 1.1.11). |
public
boolean
|
|
public
boolean
|
|
protected
boolean
|
#
getIsDeleteViaPostRequest( )
Returns whether this is a DELETE request which was tunneled through POST. |
public
boolean
|
|
protected
boolean
|
|
public
boolean
|
|
protected
boolean
|
#
getIsPatchViaPostRequest( )
Returns whether this is a PATCH request which was tunneled through POST. |
public
boolean
|
|
public
boolean
|
|
public
string
|
|
public
integer
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
array
|
#
getBrowser( string $userAgent = null )
Returns information about the capabilities of user browser. |
public
string
|
|
public
integer
|
|
public
|
|
public
integer
|
#
getSecurePort( )
Returns the port to use for secure requests. Defaults to 443, or the port specified by the server if the current request is secure. You may explicitly specify it by setting the setSecurePort securePort property. |
public
|
#
setSecurePort( integer $value )
Sets the port to use for secure requests. This setter is provided in case a custom port is necessary for certain server configurations. |
public
|
#
getCookies( )
Returns the cookie collection. The result can be used like an associative
array. Adding |
public
|
|
public static
array
|
#
parseAcceptHeader( string $header )
Parses an HTTP Accept header, returning an array map with all parts of each
entry. Each array entry consists of a map with the type, subType, baseType and
params, an array map of key-value parameters, obligatorily including a
array( 'type' => 'application', 'subType' => 'xhtml', 'baseType' => 'xml', 'params' => array( 'q' => 0.9, 'level' => '1', ), ) |
public static
integer
|
#
compareAcceptTypes( array $a, array $b )
Compare function for determining the preference of accepted MIME type array
maps See |
public
array
|
#
getPreferredAcceptTypes( )
Returns an array of user accepted MIME types in order of preference. Each
array entry consists of a map with the type, subType, baseType and params, an
array map of key-value parameters. See |
public
array
|
#
getPreferredAcceptType( )
Returns the user preferred accept MIME type. The MIME type is returned as an
array map (see |
public
array
|
#
getPreferredLanguages( )
Returns an array of user accepted languages in order of preference. The
returned language IDs will NOT be canonicalized using |
public
string
|
#
getPreferredLanguage( array $languages = array() )
Returns the user-preferred language that should be used by this application. The language resolution is based on the user preferred languages and the languages supported by the application. The method will try to find the best match. |
public
|
|
public
|
|
public
string
|
#
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. |
protected
|
#
createCsrfCookie( )
Creates a cookie with a randomly generated CSRF token. Initial values
specified in |
public
|
#
validateCsrfToken(
Performs the CSRF validation. This is the event handler responding to |
public
string
|
getIsInitialized()
|
public
boolean
|
$enableCookieValidation | false |
#
whether cookies should be validated to ensure they are not tampered. Defaults to false. |
public
boolean
|
$enableCsrfValidation | false |
#
whether to enable CSRF (Cross-Site Request Forgery) validation. Defaults to
false. By setting this property to true, forms submitted to an Yii Web
application must be originated from the same application. If not, a 400 HTTP
exception will be raised. Note, this feature requires that the user client
accepts cookie. You also need to use |
public
string
|
$csrfTokenName | 'YII_CSRF_TOKEN' |
#
the name of the token used to prevent CSRF. Defaults to 'YII_CSRF_TOKEN'.
This property is effectively only when |
public
array
|
$csrfCookie |
|
#
the property values (in name-value pairs) used to initialize the CSRF cookie.
Any property of |
$behaviors
|
public
string
|
$url |
#
Part of the request URL after the host info. |
public
string
|
$hostInfo |
#
Schema and hostname part (with port number if needed) of the request URL (e.g. http://www.yiiframework.com). |
public
string
|
$baseUrl |
#
The relative URL for the application. |
public
string
|
$scriptUrl |
#
The relative URL of the entry script. |
public
string
|
$pathInfo |
#
Part of the request URL that is after the entry script and before the question mark. Note, the returned pathinfo is decoded starting from 1.1.4. Prior to 1.1.4, whether it is decoded or not depends on the server configuration (in most cases it is not decoded). |
public
string
|
$requestUri |
#
The request URI portion for the currently requested URL. |
public
string
|
$queryString |
#
Part of the request URL that is after the question mark. |
public
boolean
|
$isSecureConnection |
#
If the request is sent via secure channel (https). |
public
string
|
$requestType |
#
Request type, such as GET, POST, HEAD, PUT, PATCH, DELETE. |
public
boolean
|
$isPostRequest |
#
Whether this is a POST request. |
public
boolean
|
$isDeleteRequest |
#
Whether this is a DELETE request. |
public
boolean
|
$isPutRequest |
#
Whether this is a PUT request. |
public
boolean
|
$isPatchRequest |
#
Whether this is a PATCH request. |
public
boolean
|
$isAjaxRequest |
#
Whether this is an AJAX (XMLHttpRequest) request. |
public
boolean
|
$isFlashRequest |
#
Whether this is an Adobe Flash or Adobe Flex request. |
public
string
|
$serverName |
#
Server name. |
public
integer
|
$serverPort |
#
Server port number. |
public
string
|
$urlReferrer |
#
URL referrer, null if not present. |
public
string
|
$userAgent |
#
User agent, null if not present. |
public
string
|
$userHostAddress |
#
User IP address. |
public
string
|
$userHost |
#
User host name, null if cannot be determined. |
public
string
|
$scriptFile |
#
Entry script file path (processed w/ realpath()). |
public
array
|
$browser |
#
User browser capabilities. |
public
string
|
$acceptTypes |
#
User browser accept types, null if not present. |
public
integer
|
$port |
#
Port number for insecure requests. |
public
integer
|
$securePort |
#
Port number for secure requests. |
public
array
|
$preferredAcceptType |
#
The user preferred accept type as an array map, e.g. array('type' => 'application', 'subType' => 'xhtml', 'baseType' => 'xml', 'params' => array('q' => 0.9)). |
public
array
|
$preferredAcceptTypes |
#
An array of all user accepted types (as array maps like array('type' => 'application', 'subType' => 'xhtml', 'baseType' => 'xml', 'params' => array('q' => 0.9)) ) in order of preference. |
public
string
|
$preferredLanguage |
#
The user preferred language. |
public
array
|
$preferredLanguages |
#
An array of all user accepted languages in order of preference. |
public
string
|
$csrfToken |
#
The random token for CSRF validation. |
$isInitialized
|