Answer the question
In order to leave comments, you need to log in
How to make friends composite and mobile version of the site?
Hello.
Composite was included on the site. The task was to make a mobile version. I created a new template, implemented a mob in it. version. In the site settings, I specified that the mobile template should be loaded using the PHP expression siteType=='pda' .
init.php
require_once($_SERVER["DOCUMENT_ROOT"]."/include/Mobile_Detect.php");
$detect = new Mobile_Detect();
$flag = $detect->isMobile();
if (strpos($APPLICATION->GetCurDir(), '/product/')!== false || strpos($APPLICATION->GetCurDir(), '/catalog/')!== false || $APPLICATION->GetCurPage(false) === '/') {
if (!$detect->isMobile()) {
setcookie('siteType', '', time()+3600*24*30,'/');
define('siteType','');
setcookie("MOBILE_VISITOR_MB", "", time()-1000);
} else {
if (isset ($_GET['type'])){
switch ($_GET['type']) {
case 'pda':
setcookie('siteType', 'pda', time()+3600*24*30,'/');
define('siteType','pda');
break;
default:
setcookie('siteType', '', time()+3600*24*30,'/');
setcookie("MOBILE_VISITOR_MB", "", time()-1000);
define('siteType','original');
}
}
else{
$checkType='';
if (isset($_COOKIE['siteType'])) $checkType=$_COOKIE['siteType'];
switch ($checkType) {
case 'pda':
define('siteType','pda');
break;
default:
define('siteType','');
setcookie("MOBILE_VISITOR_MB", "", time()-1000);
}
}
}
} else {
define('siteType','');
setcookie("MOBILE_VISITOR_MB", "", time()-1000);
}
require_once($_SERVER["DOCUMENT_ROOT"]."/include/Mobile_Detect.php");
$detect = new Mobile_Detect();
$flag = $detect->isMobile();
if (strpos($APPLICATION->GetCurDir(), '/product/')!== false || strpos($APPLICATION->GetCurDir(), '/catalog/')!== false || $APPLICATION->GetCurPage(false) === '/') {
$VISITOR_ID = $APPLICATION->get_cookie("MOBILE_VISITOR_MB");
if (($detect->isMobile()) && empty($VISITOR_ID)) {
$APPLICATION->set_cookie("MOBILE_VISITOR_MB", "MOBILE", time() + 60 * 60);
LocalRedirect("https://".$_SERVER["SERVER_NAME"] . $_SERVER["REDIRECT_URL"] . "?type=pda");
exit();
}
}
require_once($_SERVER["DOCUMENT_ROOT"]."/include/Mobile_Detect.php");
$detect = new Mobile_Detect();
$flag = $detect->isMobile();
if (strpos($APPLICATION->GetCurDir(), '/product/')!== false || strpos($APPLICATION->GetCurDir(), '/catalog/')!== false || $APPLICATION->GetCurPage(false) === '/') {
if (!$detect->isMobile()) {
$APPLICATION->set_cookie("MOBILE_VISITOR_MB", "", time() - 60 * 60);
LocalRedirect("https://".$_SERVER["SERVER_NAME"] . $_SERVER["REDIRECT_URL"] . "?type=original");
exit();
}
}
Answer the question
In order to leave comments, you need to log in
Did you try to connect all the necessary scripts for this at the init.php level, before the start of the Bitrix layers?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question