2017-10-23 11 views
0

私のコードは次のエラーを投げている:PHPは、ヘッダー情報を変更することはできません - 入力フォームを使用して

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

は、実際のコードの問題がここにあるように思わ:

<?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; 
} 
?> 

マイページ全体のコードは次のとおりです。

<!-- 
    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();を複数の場所に置いてみましたが運がありませんでした。助けてもらえますか?

+0

これらのHTMLコメントをPHPブロックの下にスローする –

+0

あるいは、より安全に、コンテンツをPHPコメントに移動することができます。 – chris85

答えて

3

このすべて削除:この以前から

<!-- 
    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; 
} 
?> 

<?phpがあまりにもそれを削除する前にスペースがあります。ヘッダーの前に出力があればエラーになります。

+0

偉大な、それは問題を修正するようです – John

+1

@ GrumpyCrouton彼らは出力の一部であるHTMLコメントです、彼らはエラーが発生します。 – mega6382

+0

@ mega6382うーん、私はちょうど私のサーバー上でそれをテストし、それが働いた。私はそれがスペースを持っているので、私のサーバーで奇妙なものだと思うそれもそれを壊すことはありません。みんなありがとう! – GrumpyCrouton

関連する問題