标题“警告:无法修改标题 - ”但也有移动重定向脚本

时间:2013-09-29 18:22:16

标签: php html css header warnings

我尝试在网站上搜索"警告:无法修改标头信息 - 已经发送的标头(输出 /起始于/home/zenithda/public_html/www.thanow.com/index .php:12)在/home/zenithda/public_html/www.thanow.com/index.php第52行。

我查看了其他示例,但我找不到与我的问题类似的问题。 我正在为我的网站的移动版本运行移动重定向脚本。我还在我的includes文件夹中运行了header.php和footer.php。但是,当我尝试通过我的android访问我的网站时,我收到了上述警告。有人试图检查他们的iPhone并发生了同样的事情。警告下方显示该站点的桌面版本。 在我的index.php中,这是直接显示在我的第一个命令之上的代码(这个论坛不会让我正确显示此代码之前的内容,这里有什么代码" !Doctype Html,大约三行!如果ie7,8,9行,一个html头,一些元charset =" utf-8"标题和元描述和关键字。另外=之前没有空格PHP命令。)

<?php


  //Load the Mobile Detection library
  include("js/mobiledetect.php");

  //In this simple example, we'll store the alternate home page file names.
  $iphoneTierHomePage = 'mobile/index.html';
  $genericMobileDeviceHomePage = 'mobile/index.html';


  //Instantiate the object to do our testing with.
  $uagent_obj = new uagent_info();


  //This is a common mobile detection scenario...
  // First, detect iPhone tier devices, like iPod Touches, Android, WebOS, etc. 
  //    Send them to the nice touch-optimized page. 
  //    These often have rich CSS and advanced but mobile-friendly JavaScript functionality and no Flash.
  // Second, detect any other mobile device. Send them to the basic mobile pages, with light CSS and no JavaScript.
  //    Some (often older) touch devices might be included in this bunch, which otherwise includes feature phones.
  //    It's a Best Practice to include an alternate web page for less-capable mobile devices. 
  // Finally, assume anything else not caught by these filters is a desktop PC-class device. 
  //    Send them to your regular home page which may include large pictures, lots of JS, Flash, etc.. 
  //
  // NOTE: If you wanted an iPad-class tablet-optimized web site, too, then you should FIRST do a 
  //    device detection using the DetectTierTablet() method. Then detect for iPhone tier, and so on. 


  //In this simple example, we simply re-route depending on which type of device it is.
  //Before we can call the function, we have to define it. 
  function AutoRedirectToProperHomePage()
  {
      global $uagent_obj, $iphoneTierHomePage, $genericMobileDeviceHomePage;

    //We have variables for certain high-usage device variables, like the iPhone Tier.
    //   You might use the device variables to show/hide certain functionality or platform-specific features and ads, etc.
    //   Alternately, you can use the method: DetectTierIphone().
    //   Sometimes, you may wish to include the Tablet Tier devices here, as well. 
      if ($uagent_obj->isTierIphone == $uagent_obj->true) 
      header ('Location: '.$iphoneTierHomePage);

    //We can generally use the Quick Mobile detection method to save a couple of cycles.
      else if ($uagent_obj->DetectMobileQuick() == $uagent_obj->true) 
      header ('Location: '.$genericMobileDeviceHomePage);

    //We'll assume that anything else not caught in the above filters is a desktop-class device. 
    //   (Which can include tablets.)
    }

  //Now, we can call the redirect function.
  AutoRedirectToProperHomePage();
?>

之后是这一行:

    <?php include 'includes/header.php' ?>

3 个答案:

答案 0 :(得分:1)

您尝试在其他输出已发送到浏览器后发送/修改HTTP标头 - 什么不起作用。 您需要在脚本开头修改标头或在修改标头之前缓冲输出。 ob_start()启动输出缓冲,在发送/标头的代码之后,您可以使用ob_end_flush()发送缓冲区。

http://www.php.net/manual/en/ref.outcontrol.php

答案 1 :(得分:0)

您可以尝试以下步骤来找出问题

  1. 检查包含文件(“js / mobiledetect.php”),在关闭PHP标记后打开PHP标记或空格之前是否有空格。
  2. 确保没有简单的回声或直接尝试打印任何html标签(不调用任何功能
  3. 检查包含文件功能之外是否有任何HTML评论部分

答案 2 :(得分:0)

确保在标题重定向之前没有任何html输出。如果您有一些输出,则会出现该错误。我认为使用元刷新标签更适合重定向。