0

私は自分の人生をずっと楽にして、すべてのページに 1 つのファイルから同じフッターとヘッド コンテンツを持たせようとしています。

コンテンツのあるページ

<?php
include ("content.php");

echo $page_header;

?>

<div id="content">
</div>

<?php

echo $page_footer;

?>

content.php

<?php

    // This is the header which we want to have on all pages
    $page_header = include ("resources/content/header.php");

    // This is the footer which we want on all pages
    $page_footer = include ("resources/content/footer.php");

?>

Header.php の例

<html>
    <head>
        <title>This is my title</title>
    </head>
    <body>
        <div id="logo">
        </div>

Footer.php の例

        <div id="footer">Copyright to me!</div>
    </body>
</html>

私が抱えている問題は、header.php コンテンツがすべて表示されず、ページの書式設定に問題があることです。header.php には、いくつかの phpifステートメントといくつかのインライン JavaScript が含まれています...これは問題でしょうか?

それを行うより良い方法はありますか?

注意: 私はローカルで PHP 5 を使用しており、私のサーバーは PHP 4 であるため、答えは両方で機能する必要があります。

4

1 に答える 1