dongqidi2799 2017-10-23 20:31
浏览 34
已采纳

PHP无法修改标题信息 - 使用输入表单[重复]

This question already has an answer here:

My code is throwing the following error:

Warning: Cannot modify header information - headers already sent by (output started at /Users/johns/Desktop/Test/index.php:5) in /Users/johns/Desktop/Test/index.php on line 7

The actual code issue seems to be here:

<?php
if (isset($_GET["googlesearch"])) {
    header("Location: https://www.test.com/#!q=" . $_GET["googlesearch"] . "&page=0&refinements=%5B%5D&numerics_refinements=%7B%7D&index_name=%22_default_products%22");
    exit;
}
?>

My full page code is :

<!--
     This is the minimum valid AMP HTML document. Just type away
     here and the AMP Playground will render your document on the fly.
-->
 <?php
if (isset($_GET["googlesearch"])) {
    header("Location: https://www.test.com/#!q=" . $_GET["googlesearch"] . "&page=0&refinements=%5B%5D&numerics_refinements=%7B%7D&index_name=%22_default_products%22");
    exit;
}
?>
<!doctype html>
<html ⚡>
<head>
  <meta charset="utf-8">
  <link rel="canonical" href="self.html" />
  <meta name="viewport" content="width=device-width,minimum-scale=1">
  <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
  <script async src="https://cdn.ampproject.org/v0.js"></script>
  <!-- Custom CSS -->
  <style amp-custom>
    <?php include './components/skin/style/css/base.css'; ?>
  </style>
</head>
<body>
  <!-- Search bar -->
  <div class="sidebar">

    <form method="GET"
          class="p2"
          action="<?php echo $_SERVER['PHP_SELF']; ?>"
          target="_top">
        <div class="ampstart-input inline-block relative mb3">
            <input type="search"
                   placeholder="Search..."
                   name="googlesearch">
        </div>
        <input type="submit"
               value="OK"
               class="ampstart-btn caps">
    </form>

  </div>
</body>
</html>

I have tried placing ob_start(); on multiple places but with no luck. Can someone help?

</div>
  • 写回答

1条回答 默认 最新

  • douzhao1912 2017-10-23 20:33
    关注

    Remove all this:

    <!--
         This is the minimum valid AMP HTML document. Just type away
         here and the AMP Playground will render your document on the fly.
    -->
    

    From Before this:

    <?php
    if (isset($_GET["googlesearch"])) {
        header("Location: https://www.test.com/#!q=" . $_GET["googlesearch"] . "&page=0&refinements=%5B%5D&numerics_refinements=%7B%7D&index_name=%22_default_products%22");
        exit;
    }
    ?>
    

    There is a space before <?php remove that too. If any output is sent before headers it will give error.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)