View Full Version : PHP include code not working

05-28-2011, 05:58 PM

I am new to PHP. I am designing a website and would like to use the same header & footer throughout the site. It is my understanding I can take the header code and save it as a php file, then use a php include to pull it into each page.

I tried the process and it didn't work. When I look at the page source I see the php statement instead of the HTML code.

I am certain my web server has php. In order to install forum software I ran a pre-requisite check which confirm it. Also I tried running the following code:


What returned was a display page showing my PHP information.

I saved the below code as header.php

<div id="header">
<div class="pageWidth">
<div id="headerContent">
<div class="screenShot">
<img src="images/makati_condo_skyline.jpg" alt="Makati night view" width="960" height="212" />

<ul id="nav">
<li class="selected"><a href=".">Home</a></li>
<li><a href="view.html">Photos</a></li>
<li><a href="rent.html">Availability & Rates</a></li>
<li><a href="makati.html">Makati Info</a></li>
<li><a href="about.html">Contact Us</a></li>

In the body of my index.html file I added the following line:

<?php include("header.php"); ?>

My header did not appear, the source shows that exact line of code. Any ideas of what I am doing wrong?

05-28-2011, 06:18 PM
<?php include("header.php"); ?> ABOVE the <html> tag.

05-28-2011, 06:40 PM
Thanks for the suggestion. That did not work.

My View Source appears as follows when I tried:

<?php include("header.php"); ?>

05-28-2011, 07:21 PM
In the body of my index.html file I added the following line ...

You will need to rename your index to index.php if you use a php include I believe - give that a try. :)

Your include should go where you want the header to appear ...


05-28-2011, 07:56 PM
In the body of my index.html file I added the following line:

Why on earth would you call you index file .html yet put php code inn it to include other .php files?

.html = No php execution*
.php = php execution

*Typical server setup

05-29-2011, 03:17 PM
Thank you Daf. That worked.

@Tangoforce, I have never worked with php. I searched for a solution to include page headers & footers in a html file so the code did not have to be copied/pasted to every page. I came across this method. The instruction to change the file type from html to php was not offered.

I have now learned that a html file can be renamed with the php extension and it will still work.

Thanks for the help!