Attention
TYPO3 v10 has reached end-of-life as of April 30th 2023 and is no longer being maintained. Use the version switcher on the top left of this page to select documentation for a supported version of TYPO3.
Need more time before upgrading? You can purchase Extended Long Term Support (ELTS) for TYPO3 v10 here: TYPO3 ELTS.
TYPO3 Request Object¶
The TYPO3 request object is a PSR-7 based ServerRequest object containing a TYPO3-specific attribute object for normalized
server parameters. These normalized parameter for instance resolve variables
if the instance is behind a reverse proxy.
Important
This substitutes GeneralUtility::getIndpEnv().
The object is available from ServerRequestInterface $request objects as an attribute.
The request object is passed to controllers, example:
/** @var NormalizedParams $normalizedParams */
$normalizedParams = $request->getAttribute('normalizedParams');
$requestPort = $normalizedParams->getRequestPort();
The request object is also available as a global variable in $GLOBALS['TYPO3_REQUEST']. This is a workaround for
the core which has to access the server parameters at places where $request is not available. So, while this object is
globally available during any HTTP request, it is considered bad practice to use this global object if the request is
accessible in another, official way. The global object is scheduled to vanish at a later point once the code has been refactored
enough to not rely on it anymore.
Migrating from GeneralUtility::getIndpEnv()¶
Class NormalizedParams is a one-to-one transition of GeneralUtility::getIndpEnv(), the old
arguments can be substituted with these calls:
SCRIPT_NAMEis now->getScriptName()SCRIPT_FILENAMEis now->getScriptFilename()REQUEST_URIis now->getRequestUri()TYPO3_REV_PROXYis now->isBehindReverseProxy()REMOTE_ADDRis now->getRemoteAddress()HTTP_HOSTis now->getHttpHost()TYPO3_DOCUMENT_ROOTis now->getDocumentRoot()TYPO3_HOST_ONLYis now->getRequestHostOnly()TYPO3_PORTis now->getRequestPort()TYPO3_REQUEST_HOSTis now->getRequestHost()TYPO3_REQUEST_URLis now->getRequestUrl()TYPO3_REQUEST_SCRIPTis now->getRequestScript()TYPO3_REQUEST_DIRis now->getRequestDir()TYPO3_SITE_URLis now->getSiteUrl()TYPO3_SITE_PATHis now->getSitePath()TYPO3_SITE_SCRIPTis now->getSiteScript()TYPO3_SSLis 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_INFOis now->getPathInfo(), but better use->getScriptName()insteadHTTP_REFERERis now->getHttpReferer(), but better use$request->getServerParams()['HTTP_REFERER']insteadHTTP_USER_AGENTis now->getHttpUserAgent(), but better use$request->getServerParams()['HTTP_USER_AGENT']insteadHTTP_ACCEPT_ENCODINGis now->getHttpAcceptEncoding(), but better use$request->getServerParams()['HTTP_ACCEPT_ENCODING']insteadHTTP_ACCEPT_LANGUAGEis now->getHttpAcceptLanguage(), but better use$request->getServerParams()['HTTP_ACCEPT_LANGUAGE']insteadREMOTE_HOSTis now->getRemoteHost(), but better use$request->getServerParams()['REMOTE_HOST']insteadQUERY_STRINGis now->getQueryString(), but better use$request->getServerParams()['QUERY_STRING']instead