Documentation

GetSiteByAcceptLanguage

mixed
CMainPage::GetSiteByAcceptLanguage(
 bool compare_site_id = false
)

The method 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. Non-static method.

Function parameters

ParameterDescription Available from version
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 parameter. By default value is false.

Example of index page

If you intend to use the below example as the index page, please ensure:
1. Your sites use "Mode 1. Single web server for all sites" 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");?>


© «Bitrix24», 2001-2024
Up