dounue1965 2015-12-28 08:36
浏览 38
已采纳

PHP - 从另一个文件加载标头

I've run into problem whereby I'm not able to include a header file into a PHP file

In the code below, I've removed the original content as it's quite big & anyway what the code does is irrelevant to including the header file

MAIN.PHP

        <?php
 php content
            ?>


            <html>
    <head>  
            </head>
                <body >
                <div>
                   header content
                    </div>

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

I would like to have the following code in the header.php file & include it on all pages.

            <div>
header content
</div>

When I do so with the main.php file looking as below, the page draws blank.

      <?php
 php content
            ?>


            <html>
    <head>  
            </head>
                <body >
                <div>
                   <? php include('header.php') ?>
                    </div>

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

I've tried debugging this & following a few solutions on stackoverflow, but evidently have failed to achieve what I'm after.

Could I please request a second pair of eyes to help me spot the problem?

  • 写回答

1条回答 默认 最新

  • duanchai0028 2015-12-28 08:49
    关注

    Well, first of all, I don't think you copied the code correctly to here. As my debugging eyes can see, you got 2 issues:

    1. Line 1: < is missing at the start. Change it to <?php. (Maybe copy paste error?)
    2. <?php include('header.php'); is missing closing tag. Change it to: <?php include('header.php'); ?>

    If you get a blank page, you probably have some errors. Try finding the "error.log" file in you working directory or add the following code at the start of the page:

    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog