Normalized parameters¶
The normalizedParams
request attribute provide access to server
parameters, for instance, if the TYPO3 installation is behind a reverse proxy.
It is available in frontend and backend context.
Attention
The normalized parameters substitute
\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv()
. See the
migration guide below.
One can retrieve the normalized parameters like this:
/** @var \TYPO3\CMS\Core\Http\NormalizedParams $normalizedParams */
$normalizedParams = $request->getAttribute('normalizedParams');
$requestPort = $normalizedParams->getRequestPort();
API¶
- class TYPO3\CMS\Core\Http\NormalizedParams¶
This class provides normalized server parameters in HTTP request context.
It normalizes reverse proxy scenarios and various other web server specific differences of the native PSR-7 request object parameters (->getServerParams() / $GLOBALS['_SERVER']).
An instance of this class is available as PSR-7 ServerRequestInterface attribute:
$normalizedParams = $request->getAttribute('normalizedParams')
This class substitutes the old GeneralUtility::getIndpEnv() method.
- getDocumentRoot()¶
- Return type
string
- Returns
Absolute path to web document root, eg. /var/www/typo3
- getHttpAcceptEncoding()¶
Will be deprecated later, use $request->getServerParams()['HTTP_ACCEPT_ENCODING'] instead
- Return type
string
- Returns
HTTP_ACCEPT_ENCODING, eg. 'gzip, deflate'
- getHttpAcceptLanguage()¶
Will be deprecated later, use $request->getServerParams()['HTTP_ACCEPT_LANGUAGE'] instead
- Return type
string
- Returns
HTTP_ACCEPT_LANGUAGE, eg. 'de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7'
- getHttpHost()¶
- Return type
string
- Returns
Sanitized HTTP_HOST value host[:port]
- getHttpReferer()¶
Will be deprecated later, use $request->getServerParams()['HTTP_REFERER'] instead
- Return type
string
- Returns
HTTP_REFERER, eg. 'https://www.domain.com/typo3/index.php?id=42'
- getHttpUserAgent()¶
Will be deprecated later, use $request->getServerParams()['HTTP_USER_AGENT'] instead
- Return type
string
- Returns
HTTP_USER_AGENT identifier
- getQueryString()¶
Will be deprecated later, use $request->getServerParams()['QUERY_STRING'] instead
- Return type
string
- Returns
QUERY_STRING, eg 'id=42&foo=bar'
- getPathInfo()¶
Will be deprecated later, use getScriptName() as reliable solution instead
- Return type
string
- Returns
Script path part of URI, eg. 'typo3/index.php'
- getRemoteAddress()¶
- Return type
string
- Returns
Client IP
- getRemoteHost()¶
Will be deprecated later, use $request->getServerParams()['REMOTE_HOST'] instead
- Return type
string
- Returns
REMOTE_HOST if configured in web server, eg. 'www.clientDomain.com'
- getRequestDir()¶
- Return type
string
- Returns
REQUEST URI without script file name and query parts, eg. http://www.domain.com/typo3/
- getRequestHost()¶
- Return type
string
- Returns
Sanitized HTTP_HOST with protocol scheme://host[:port], eg. https://www.domain.com/
- getRequestHostOnly()¶
- Return type
string
- Returns
Host / domain /IP only, eg. www.domain.com
- getRequestPort()¶
- Return type
int
- Returns
Requested port if given, eg. 8080 - often not explicitly given, then 0
- getRequestScript()¶
- Return type
string
- Returns
REQUEST URI without query part, eg. http://www.domain.com/typo3/index.php
- getRequestUri()¶
- Return type
string
- Returns
Request Uri without domain and protocol, eg. /index.php?id=42
- getRequestUrl()¶
- Return type
string
- Returns
Full REQUEST_URI, eg. http://www.domain.com/typo3/foo/bar?id=42
- getScriptFilename()¶
- Return type
string
- Returns
Absolute entry script path on server, eg. /var/www/typo3/index.php
- getScriptName()¶
- Return type
string
- Returns
Script path part of URI, eg. '/typo3/index.php'
- getSitePath()¶
- Return type
string
- Returns
Path part to frontend, eg. /some/sub/dir/
- getSiteScript()¶
- Return type
string
- Returns
Path part to entry script with parameters, without sub dir, eg 'typo3/index.php?id=42'
- getSiteUrl()¶
- Return type
string
- Returns
Website frontend url, eg. https://www.domain.com/some/sub/dir/
- isBehindReverseProxy()¶
- Return type
bool
- Returns
True if request comes from a configured reverse proxy
- isHttps()¶
- Return type
bool
- Returns
True if client request has been done using HTTPS
Migrating from GeneralUtility::getIndpEnv()
¶
The class \TYPO3\CMS\Core\Http\NormalizedParams
is a one-to-one transition
of \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv()
, the old
arguments can be substituted with these calls:
SCRIPT_NAME
is now->getScriptName()
SCRIPT_FILENAME
is now->getScriptFilename()
REQUEST_URI
is now->getRequestUri()
TYPO3_REV_PROXY
is now->isBehindReverseProxy()
REMOTE_ADDR
is now->getRemoteAddress()
HTTP_HOST
is now->getHttpHost()
TYPO3_DOCUMENT_ROOT
is now->getDocumentRoot()
TYPO3_HOST_ONLY
is now->getRequestHostOnly()
TYPO3_PORT
is now->getRequestPort()
TYPO3_REQUEST_HOST
is now->getRequestHost()
TYPO3_REQUEST_URL
is now->getRequestUrl()
TYPO3_REQUEST_SCRIPT
is now->getRequestScript()
TYPO3_REQUEST_DIR
is now->getRequestDir()
TYPO3_SITE_URL
is now->getSiteUrl()
TYPO3_SITE_PATH
is now->getSitePath()
TYPO3_SITE_SCRIPT
is now->getSiteScript()
TYPO3_SSL
is now->isHttps()
Some further old getIndpEnv()
arguments directly access $request->serverParams()
and do not apply any
normalization. These have been transferred to the new class, too, but will be deprecated later if the Core does not use
them anymore:
PATH_INFO
is now->getPathInfo()
, but better use->getScriptName()
insteadHTTP_REFERER
is now->getHttpReferer()
, but better use$request->getServerParams()['HTTP_REFERER']
insteadHTTP_USER_AGENT
is now->getHttpUserAgent()
, but better use$request->getServerParams()['HTTP_USER_AGENT']
insteadHTTP_ACCEPT_ENCODING
is now->getHttpAcceptEncoding()
, but better use$request->getServerParams()['HTTP_ACCEPT_ENCODING']
insteadHTTP_ACCEPT_LANGUAGE
is now->getHttpAcceptLanguage()
, but better use$request->getServerParams()['HTTP_ACCEPT_LANGUAGE']
insteadREMOTE_HOST
is now->getRemoteHost()
, but better use$request->getServerParams()['REMOTE_HOST']
insteadQUERY_STRING
is now->getQueryString()
, but better use$request->getServerParams()['QUERY_STRING']
instead