usert4jju7
usert4jju7

Reputation: 1813

PHP - Load header from another file

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?

Upvotes: 0

Views: 2225

Answers (1)

Gal Silberman
Gal Silberman

Reputation: 3884

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);

Upvotes: 4

Related Questions