Bitrix Site Manager

CMainPage::GetSiteByAcceptLanguage

mixed
CMainPage::GetSiteByAcceptLanguage(
 bool compare_site_id = false
)

The method GetSiteByAcceptLanguage returns the site ID by the Accept-Language variable in the user browser settings. The language order reported by the user browser settings defines the language selection priority for this function. If none of these languages can be found appropriate, a site whose flag Site by default is set will be selected.

Parameters

ParameterDescription
compare_site_id If the value is true, the search will be performed by matching the language identifier from Accept-Language against the site ID. If set to false, the search will be performed by matching the language identifier against the language ID taken from site settings.

Optional. False by default.

See Also

Example

Note!
If you intend to use the below example as the index page, please ensure:
1. Your sites use method 1 to make multiple sites environment.
2. None of sites has a value of "/" in the field Site Folder.

<?
require($_SERVER['DOCUMENT_ROOT']."/bitrix/modules/main/include/mainpage.php");

if ($sid = CMainPage::GetSiteByAcceptLanguage())
    CMainPage::RedirectToSite($sid);

require($_SERVER['DOCUMENT_ROOT']."/bitrix/header.php");?>
<?require($_SERVER['DOCUMENT_ROOT']."/bitrix/footer.php");?>