开发者

PHP Mobile Detect script in Joomla 1.5

开发者 https://www.devze.com 2023-04-13 02:46 出处:网络
I\'m having problem with going from mobile page to main page implemented in Joomla 1.5. I\'m using PHP Mobile Detect script found at http://code.google.com/p/php-mobile-detect/

I'm having problem with going from mobile page to main page implemented in Joomla 1.5. I'm using PHP Mobile Detect script found at http://code.google.com/p/php-mobile-detect/

First I tested my script in a simple website (not Joomla). This is the actual code used (index.php):

<?php
session_start();

include("Mobile_Detect.php");
$mobile_detect = new Mobile_Detect();

if (isset($_GET['ua']) && $_GET['ua']==1){
    $_SESSION['sitemode'] = 1;
}elseif (isset($_GET['ua']) && $_GET['ua']==0){
    unset($_SESSION['sitemode']);
}    
if ($mobile_detect->isMobile() && !isset($_SESSION['sitemode'])) {
    // any mobile platform
    header('Location: mobile/');
}
// site related codes goes here...
?>

So, when the website is accessed using a mobile device it will redirect to the mobile website (subfolder in wwwroot). When in the mobile website, user can choose to use the main website instead by a provided link (this is in mobile/index.php):

<a href="../index.php?ua=1">Fullsite</a>

Session is also enabled in the mobile page.

Then when in main, user are able to browse to other pages of the main website without being redirected to the mobile page. This works perfectly on the standalone php script with index.php in root as the bootstrap.

However, when I try to implement it in Joomla, it only works on the first redirect. When I browse to other pages in the Joo开发者_JAVA百科mla site it redirects to the mobile page. The script above is added at the top of Joomla's bootstrap (index.php)

Thanks!


I figured this out quite a while back. Just got the chance to update and share the solution with anybody else who might have encountered this same problem.

All I did was moved all the codes that I have in Joomla's bootstrap as in the question above (index.php) into the template bootstrap (ex. joomla_root/templates/template_name/index.php).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号