Attention

TYPO3 v9 has reached its end-of-life September 30th, 2021 and is not maintained by the community anymore. Looking for a stable version? Use the version switch on the top left.

You can order Extended Long Term Support (ELTS) 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_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() instead

  • HTTP_REFERER is now ->getHttpReferer(), but better use $request->getServerParams()['HTTP_REFERER'] instead

  • HTTP_USER_AGENT is now ->getHttpUserAgent(), but better use $request->getServerParams()['HTTP_USER_AGENT'] instead

  • HTTP_ACCEPT_ENCODING is now ->getHttpAcceptEncoding(), but better use $request->getServerParams()['HTTP_ACCEPT_ENCODING'] instead

  • HTTP_ACCEPT_LANGUAGE is now ->getHttpAcceptLanguage(), but better use $request->getServerParams()['HTTP_ACCEPT_LANGUAGE'] instead

  • REMOTE_HOST is now ->getRemoteHost(), but better use $request->getServerParams()['REMOTE_HOST'] instead

  • QUERY_STRING is now ->getQueryString(), but better use $request->getServerParams()['QUERY_STRING'] instead