1

2つのphpページがあります.1つはメインで2つ目を含み、exp​​iresヘッダーを追加したいのですが、次のエラーが発生します

    Warning: Cannot modify header information -
 headers already sent by (output started at.. 

最初のもので

ob_start('ob_gzhandler', 6);

/// lots of html here

include("pageTwo.php");

/// lots of html here

ob_end_flush();

2ページ目

ob_start();
header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));

/// lots of html here

ob_end_flush();
4

3 に答える 3

1

モードを使用せず、圧縮を適用する前に6で実行してみてください。

<?php
ob_start();

// include ...

ob_end_flush();
?>
于 2012-05-16T04:37:57.003 に答える
0

PHPページが出力を生成する前に、ヘッダーを送信する必要があります。

これは機能しません

<?php 
     print 'test';
     header( 'Expires: .... ' );
?>

これは機能します:

<?php
     header( 'Expires: .... ' );
     print 'test';
?>

したがって、基本的に、ヘッダーを送信するページを変更する必要があります。

于 2012-05-16T04:36:14.067 に答える
0

ヘッダーが最初に配置され、通常のテキストとしては表示されないため、ヘッダーの前に文字列をエコーするものを配置することはできません。通常のメタタグを追加できます。そして、phpの例で有効期限を設定します

  <meta http-equiv="expires" content="<?php echo date(whatever type); ?>" />
于 2012-05-16T04:41:08.823 に答える