首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP不能修改头信息--使用输入表单

PHP不能修改头信息--使用输入表单
EN

Stack Overflow用户
提问于 2017-10-23 20:31:16
回答 1查看 60关注 0票数 0

我的代码抛出了以下错误:

警告:无法修改标题信息-第7行中的/Users/Desktop/Test/index.php:5中已经由/Users/johns/Desktop/Test/index.php :5发送的标题

实际的代码问题似乎就在这里:

代码语言:javascript
复制
<?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;
}
?>

我的完整页面代码是:

代码语言:javascript
复制
<!--
     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>

我尝试过将ob_start();放置在多个地方,但没有运气。有人能帮忙吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-10-23 20:33:54

删除所有这些:

代码语言:javascript
复制
<!--
     This is the minimum valid AMP HTML document. Just type away
     here and the AMP Playground will render your document on the fly.
-->

在此之前:

代码语言:javascript
复制
<?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;
}
?>

<?php删除之前也有一个空格。如果在标头之前发送任何输出,则会出现错误。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46897985

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档