View Full Version : Trying to figure out header and content issues (loading them into existing pages)

05-16-2010, 03:10 PM
Sorry in advance if my question seems trivial.

Basically, every single page of mine has its own header and content code instead of it being in blocks and linking with various pages within the root directory making those blocks as individual pages/pieces.

For example, I want a header.html or a header.php so if I make changes to my header, I can update only the header.html or the header.php and not have to go into every single page of mine and redundantly update it.

I figured out how I had to link this correctly by creating an external css file. I can't figure it out for the header, and other content on my website. Can anyone help me out or give me the direction I am supposed to go in figuring this out?

Thank you once again in advance...

05-16-2010, 03:29 PM
Going PHP is easy if you want that route, name your page pagewhatever.php
and put something like this at the top


$page_title = "Articles & Research";

$page_description = "Description of this page";

$image = "Images/Articles-Research.gif";


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

Then name your link page header.php (or whatever you want to call it .php)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title><?php echo $page_title; ?></title>
<meta http-equiv="description" content="<?php echo $page_description; ?>" />
<link rel="shortcut icon" href="favicon.ico">
<link type="text/css" rel="stylesheet" href="../navmenu/navmenu.css"/>
<link type="text/css" rel="stylesheet" href="../css/css1.css"/>
<script type="text/javascript" src="../navmenu/navmenu.js"></script>

<img class="style10" height="105" src="<?php echo $image; ?>" width="743" />
<div class="style15" style="width: 10px; background-color: #E4E4E4;">
<div style="height: 52px; width: 972px; background-color: #9FDC72; z-index: inherit;">
<div class="style13" style="width: 10px; height: 558px; background-color: #E4E4E4;">
<br />
<br />
<br />
<br />

Makes life a whole lot easier, only data you change is at the top per page and image update when wanted.
<?php echo $page_title; ?> is you place holder
$page_title = "Articles & Research"; is the info that is filled into the holder
<?php include("php/header.php"); ?> is the call to place the code where you want it.


05-16-2010, 03:38 PM
Thanks soooo much for your reply! IF I don't care about the "title" of the page but just want to import the (for example) the "header.php" or "form.php" or whatever....could I just put the code: " <?php include("php/header.php"); ?> " without the other stuff? I want to import several different blocks of content....

I will play around with this but thank you again so much for your swift reply and help!

05-16-2010, 03:47 PM
One last thing; I am already linking my existing pages to an external stylesheet; can I avoid doing it for the individual .php pages since I already have it for my main page so I can just simply replace the header content on the individual pages and link it to those .php pages? Sorry for the headache and thanks again!

05-16-2010, 04:18 PM
One last thing; I am already linking my existing pages to an external stylesheet; can I avoid doing it for the individual .php pages since I already have it for my main page so I can just simply replace the header content on the individual pages and link it to those .php pages? Sorry for the headache and thanks again!

No headache at all, just slow down and look at my example, yes I use the same header to connect all my css pages
<link type="text/css" rel="stylesheet" href="../css/css1.css"/>
<link type="text/css" rel="stylesheet" href="../css/css2.css"/>

The header.php I posted I use on every page of one of my sites, I only have to change that file if I want to add a new css somewhere.
The other stuff is very nice to use, but you can leave out what you don't want. If you put a <?php echo $image; ?> in your header.php then you must use the $image = "Images/Articles-Research.gif"; format at the top. If you are going to use the same image for example on every page then skip the <echo> part and hard code it into the header.php file.

<img class="style10" height="105" src="Images/Links-Tools.gif" width="743" />


05-16-2010, 04:23 PM
Thanks...I will play around with it and will post back with results. Thank you again. :)

05-16-2010, 05:14 PM
Lori, this will work with my .html and .asp pages right (using this coding to parse the header file into my html and asp pages). Thx again :)

05-16-2010, 05:39 PM
Lori, I followed your instructions and can't figure out what I am doing wrong.

First thing, like I mentioned, I am using .html and .asp files to input these <php coding as you mentioned.

I created my header.php file or (I named it "top_seo.php" file for example) and put the php encoding as you mentioned. I then went into my html and asp pages and input "<?php include("top_seo.php"); ?>" (excluded the php folder as my files are on my root directory) and it reads nothing....am I doing something wrong?

05-16-2010, 05:46 PM
No, you need to change your .html file extensions to .php. I never touched .asp so you should probably google that. You can use all the html code on the .php page you want. Personally its just a tiny price to make maintaining easy, but it's up to you. I have a couple .html sites and a couple .php (hands down the .php is sooo much easier to update)


05-16-2010, 06:24 PM
My knowledge is limited, but I know of 2 ways to include files like headers, menus and footers:

1) Your pages can all be html and your included files can be html. You will use server side includes. Create a file for just your header and save it as header.html. This file should not have all the doctype information that we have at the top of our pages. Then put this line in your web page where you
normally have all your header information :
<!--#include file="header.html"-->
Be sure to put the path, etc to the file on your server. You will have to edit all your web pages this one time to include that line, but from then on, you can just edit that one header file and then each page will go get it each time it

IMPORTANT: For this to work you need to put a line in your htaccess file to parse the .html pages as .shtml. I think my wording in mine looks something like this:

AddHandler server-parsed .html
AddType text/html html


2.) Use PHP and use PHP includes in your pages. Your pages must be php pages. The files you include can be php or html. I have one page that includes both types of files, so that page on my site is php.

To include the html files I have this statement:

<?php include("http://domain.com/filename.html"); ?>

and to include the php files I have

<?php include("http://domain.com/filename.php"); ?>

and the included file can be as simple as just your header with whatever divs and classes it already has. If your included file is also php be sure to save it as php.

On the CSS issue, you can have all your css information in one external stylesheet. You should not need multiple stylesheets and you don't need an extra link to that in your included files. Remember the included files just pull right into your web page so there is no need to duplicate any information
from your web page. Just make sure that your stylesheet covers any of the divs and classes, etc. that you have in your included files.

I know nothing of ASP.

I hope this is helpful.


05-17-2010, 07:56 PM
It works pefectly! Thanks so much. Last question though: If I have a chat script or tracking script...will it track it correctly if the page they are on is pulling the information from an external php file? Thanks SO MUCH AGAIN for all your help. I had to convert all my files to php but it was most definitely worth it~! :)

05-20-2010, 02:38 PM
Thanks again. :) Everything has seemed to work perfectly and made things much easier thanks to you!

05-20-2010, 03:28 PM
Just a point to add, if you are using SSI or php includes you dont have to give the included file either the .html or the .php suffix. I normally use .txt or make the suffix tell you more eg. left.nav.

Also I have some sites built in html where I use SS includes and then one page (usually a form) which has the .php suffix, so it has a PHP include; by calling the include e.g. footer.txt the same file can be included by PHP and SSI.

05-20-2010, 08:36 PM

Thanks for that tip about just using a .txt file for your included files. I have found that both the ssi and the php can pull a file with the .html extension. However I guess technically that file IS just a text file because it does not have all the html header. Good information to ponder.