【问题标题】:Mobile Redirect Not Working[Tested On Multiple Mobile Devices]移动重定向不起作用[在多个移动设备上测试]
【发布时间】:2015-04-20 17:55:01
【问题描述】:

大家好,我正在使用我在另一个问题中找到的代码,该代码表示​​它已正确回答并且可以正常工作。但它对我不起作用,我已经在多个设备上尝试过了。

完整的代码可以在这里找到(这是代码库):https://raw.githubusercontent.com/serbanghita/Mobile-Detect/master/Mobile_Detect.php

问题在这里:Best way to redirect single php page for mobile devices with PHP/Javascript

我的代码是:

<?php require('includes/mobileRedirect.php'); ?>
<?php
    $detect = new Mobile_Detect;
    if ( $detect->isMobile() ) {
 header('Location: http://m.jollyrogerpcs.com/');
 exit;
}
?>

问题似乎出在“标题”区域。如果我用 echo('mobile'); 替换标题它有效,但无论我做什么,我似乎都无法让移动设备重定向。

编辑:通过在 DOCTYPE 之前移动代码解决了问题。

【问题讨论】:

  • 您检查过错误日志吗?在您打开 &lt;?php 标签后立即将错误报告添加到文件顶部:error_reporting(E_ALL); ini_set('display_errors', 1);
  • 我得到了这些:警告:无法修改标头信息 - 标头已由 /home/jollyrogerpcs/public_html/includes/ 中的(输出开始于 /home/jollyrogerpcs/public_html/index.php:3)发送第 4 行的 head.php 警告:无法修改标头信息 - 第 5 行的 /home/jollyrogerpcs/public_html/index.php:3 中的 /home/jollyrogerpcs/public_html/index.php:3 已发送标头警告:无法修改标头信息 - 标头已由第 6 行 /home/jollyrogerpcs/public_html/includes/head.php 中的(输出开始于 /home/jollyrogerpcs/public_html/index.php:3)发送
  • 就是这些行: header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache");
  • 您尝试重定向的文件已经将输出发送到浏览器。一旦发生这种情况,就无法进行重定向。
  • 没关系,我将它移到 DOCTYPE 之前,它可以工作。谢谢杰。你提到它已经输出让我想把它移到那里。

标签: php redirect mobile


【解决方案1】:

将此代码移到 DOCTYPE 之前,它就像一个魅力。

<?php require('includes/mobileRedirect.php'); 
$detect = new Mobile_Detect;
 if ( $detect->isMobile() ) {
  header('Location: http://m.jollyrogerpcs.com/');
}
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-12
    • 2014-04-22
    • 1970-01-01
    • 2017-07-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多