【问题标题】:PHP Mobile Detect script in Joomla 1.5Joomla 1.5 中的 PHP Mobile Detect 脚本
【发布时间】:2012-03-16 17:27:34
【问题描述】:

我在从移动页面转到 Joomla 1.5 中实现的主页时遇到问题。 我正在使用位于 http://code.google.com/p/php-mobile-detect/

的 PHP Mobile Detect 脚本

首先我在一个简单的网站(不是 Joomla)中测试了我的脚本。 这是实际使用的代码(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...
?>

因此,当使用移动设备访问该网站时,它将重定向到移动网站(wwwroot 中的子文件夹)。在移动网站中,用户可以通过提供的链接(在 mobile/index.php 中)选择使用主网站:

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

在移动页面中也启用了会话。

然后,在主页面中,用户可以浏览到主网站的其他页面,而不会被重定向到移动页面。这在以根目录中的 index.php 作为引导程序的独立 php 脚本上完美运行。

但是,当我尝试在 Joomla 中实现它时,它只适用于第一个重定向。当我浏览到 Joomla 站点中的其他页面时,它会重定向到移动页面。上面的脚本是在Joomla的bootstrap(index.php)顶部添加的

谢谢!

【问题讨论】:

    标签: php mobile joomla1.5


    【解决方案1】:

    我很久以前就想到了这一点。刚刚有机会更新并与可能遇到同样问题的其他人分享解决方案。

    我所做的只是将上面问题中的 Joomla 引导程序中的所有代码 (index.php) 移动到模板引导程序中(例如 joomla_root/templates/template_name/index.php)。

    【讨论】:

      猜你喜欢
      • 2013-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多