---
title: "PHP API: accessing site configuration"
manual: "TYPO3 Explained"
version: "11.5"
permalink: "https://docs.typo3.org/permalink/t3coreapi:sitehandling-php-api@11.5"
source: "ApiOverview/SiteHandling/AccessingSiteConfiguration.rst"
rendered: "2026-10-21T15:30:00+00:00"
---

# PHP API: accessing site configuration {#sitehandling-php-api}

The PHP API for sites comes in two parts:

-   Accessing the current, resolved site object
-   Finding a site object / configuration via a page or identifier

The first case is relevant when we want to access the site configuration in the
current request, for example, if we want to know which language is currently
rendered.

The second case is about accessing site configuration options independent of the
current request but based on a page ID or a site identifier.

Let us look at both cases in detail.

## Accessing the current site object {#accessing-the-current-site-object}

When rendering the frontend or backend, TYPO3 builds an HTTP request object through
a [PSR-15 middleware stack](https://docs.typo3.org/permalink/t3coreapi:request-handling@11.5) and enriches it with
information. Part of that information are the objects
`\TYPO3\CMS\Core\Site\Entity\Site` and
`\TYPO3\CMS\Core\Site\Entity\SiteLanguage`. Both objects are
available as [attributes](https://docs.typo3.org/permalink/t3coreapi:typo3-request-attributes@11.5) in the current
[request object](https://docs.typo3.org/permalink/t3coreapi:typo3-request@11.5).

Depending on the context, there are two main ways to access them:

-   via the PSR-7 HTTP request object directly - for example in a PSR-15
    middleware, an [Extbase controller](https://docs.typo3.org/permalink/t3coreapi:extbase-action-controller@11.5) or a
    [user function](https://docs.typo3.org/m/typo3/reference-typoscript/11.5/en-us/ContentObjects/UserAndUserInt/Index.html#cobj-user).
-   via `$GLOBALS['TYPO3_REQUEST']` \- everywhere you do not have a
    request object.

> [!TIP]
> **Hint**
>
> The first method is preferred if possible as `$GLOBALS['TYPO3_REQUEST']`
> was deprecated in TYPO3 v9.2 and will be removed in a future version.

Methods:

**EXT:my_extension/Classes/MyClass.php**

```php
// current site
$site = $request->getAttribute('site');

// current site language
$siteLanguage = $request->getAttribute('language');
```

<!-- TODO: no Markdown rendering for "versionchanged" -->

The Extbase request class implements the
PSR-7 \Psr\Http\Message\ServerRequestInterface. Therefore you can
retrieve all needed attributes from the request object.

## Finding a site object {#sitehandling-site-object}

When you need to access the site configuration for a specific page ID or by a
site identifier, you can use the class `\TYPO3\CMS\Core\Site\SiteFinder`.

The methods for finding a specific site throw a
`\TYPO3\CMS\Core\Exception\SiteNotFoundException` if no site was found.

### API {#api}

-   **class SiteFinder**

    -   *Fully qualified name:* `\TYPO3\CMS\Core\Site\SiteFinder`

    Is used in backend and frontend for all places where to read / identify sites and site languages.

    -   **getAllSites(bool $useCache = true)**

        Return a list of all configured sites

        -   *param bool $useCache:* the useCache, default: true
        -   *returntype:* array

    -   **getSiteByIdentifier(string $identifier)**

        Find a site by given identifier

        -   *param string $identifier:* the identifier
        -   *returntype:* TYPO3\\CMS\\Core\\Site\\Entity\\Site

    -   **getSiteByPageId(int $pageId, array $rootLine = NULL, string $mountPointParameter = NULL)**

        Traverses the rootline of a page up until a Site was found.

        -   *param int $pageId:* the pageId
        -   *param array $rootLine:* the rootLine, default: NULL
        -   *param string $mountPointParameter:* the mountPointParameter, default: NULL
        -   *returntype:* TYPO3\\CMS\\Core\\Site\\Entity\\Site

## The site object {#the-site-object}

A `\TYPO3\CMS\Core\Site\Entity\Site` object gives access to the site
configuration options via

-   `getConfiguration()`: returns the complete configuration
-   `getAttribute()`: returns a specific configuration attribute (root
    level configuration only)

Additionally, the site object provides methods for accessing related objects
(languages / errorHandling):

-   `getErrorHandler()`: returns a `PageErrorHandler` according to the
    site configuration
-   `getAvailableLanguages()`: returns languages available to a user
    (including access checks)
-   `getLanguageById()`: returns a site language object for a language ID
-   ...

Take a look at the class to find out more:
[EXT:core/Classes/Site/Entity/Site.php (GitHub)](https://github.com/typo3/typo3/blob/11.5/typo3/sysext/core/Classes/Site/Entity/Site.php).

## The site language object {#the-site-language-object}

The `SiteLanguage` object is basically a simple model that represents the
configuration options of the site regarding language as an object and provides
getters for those properties.

See [EXT:core/Classes/Site/Entity/SiteLanguage.php (GitHub)](https://github.com/typo3/typo3/blob/11.5/typo3/sysext/core/Classes/Site/Entity/SiteLanguage.php).
