Skip to content

Instantly share code, notes, and snippets.

@Elvinz
Forked from d1i1m1o1n/init.php
Created April 20, 2020 06:30
Show Gist options
  • Save Elvinz/e55c110a61cd04afa620b7138bb04726 to your computer and use it in GitHub Desktop.
Save Elvinz/e55c110a61cd04afa620b7138bb04726 to your computer and use it in GitHub Desktop.
Bitrix detect mobile devices and enable mobile template and redirect to mobile folder
<?
define("LOG_FILENAME", $_SERVER["DOCUMENT_ROOT"]."/log.txt");
//define('siteType', 'dev');
//Определяем мобильные устройства библиотекой http://mobiledetect.net/
require_once 'include/Mobile_Detect.php';
$detect = new Mobile_Detect;
//Все мобилные устройства кроме планшетов
if( $detect->isMobile() && !$detect->isTablet() ){
define('siteType', 'm');
//Если еще не перешли в раздел мобильной версии сайта
if(preg_match('/\/m\//', $_SERVER["REQUEST_URI"]) == 0) {
LocalRedirect("/m".$_SERVER["REQUEST_URI"]);
}
} else {
define('siteType', '');
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment