header
 
     
 
pixel
pixel pixel

Including your HTML headers and footers in separate php files

The thing I don't like about flat HTML files is you need to repeat the same HTML code throughout your website. Then if you need to make a change to your web design (eg - add or edit a navigation button), you have to go throughout the entire website editing each page. There are ways around this such as using Dreamweaver templates but my preferred method is to move the common HTML code into separate files header.php and footer.php. Then on each webpage, I use the php function include() to insert the header and footer HTML into each page. Then if I need to make a change throughout the website, I merely make one change in the header or footer files. Easy peasy!

So when I first develop a website, the first thing I do is create a single HTML document. By way of example, here's a typical webpage (note - it's very simple HTML):

index.php
<html>
    <head>
        <title>Website Title</title>
    </head>
    <body>
        <table>
            <tr>
                <td colspan=3>Header</td>
            </tr>
            <tr>
                <td>Left Margin</td>
                <td>Main Content</td>
                <td>Right Margin</td>
            </tr>
            <tr>
                <td colspan=3>Footer</td>
            </tr>
        </table>
    </body>
</html>

Once I've completed the HTML page and everything looks good, I break the above HTML page up into 3 separate files:

header.php
<html>
    <head>
        <title><?= $PageTitle ?></title>
    </head>
    <body>
        <table>
            <tr>
                <td colspan=3>Header</td>
            </tr>
            <tr>
                <td>Left Margin</td>
                <td>

index.php
<?php
$PageTitle 
"Website Title";
include (
'header.php');
?>
Main Content
<?php
include ('footer.php');
?>

footer.php
                </td>
                <td>Right Margin</td>
            </tr>
            <tr>
                <td colspan=3>Footer</td>
            </tr>
        </table>
    </body>
</html>

Note - to allow me to use a different title on each webpage (and every other page in the website), I use the variable $PageTitle in header.php. Of course this means that in index.php, I have to define $PageTitle before I include header.php or I'll get an undefined variable error.


Unhelpful Helpful Rating 5.0 (score out of 5, no. of ratings: 1)
Comments
Comment by 数据恢复 on 2008-04-08
专业从事数据恢复RAID数据恢复服务器数据恢复钢管加密锁数据恢复数据恢复数据恢复数据恢复数据恢复数据恢复数据恢复数据恢复数据恢复升降机幸福娱乐幸福女人娱乐博客相册树化玉 导航google排名google排名google排名台州网站建设优化推广网站建设网站优化网络公司 google左侧排名google左侧排名google排名google排名google排名google优化google排名网站优化搜索引擎优化搜索引擎排名网站优化搜索引擎优化网站推广网站优化百度优化SEO搜索引擎营销数据恢复数据恢复数据恢复SEO同声翻译SEO塑料同声传译设备租赁数据恢复数据恢复数据恢复数据恢复数据恢复台州做网站推广Hi Best wishes。bjseek by数据恢复数据恢复数据恢复 The best of luck Best wishes Best regards .by bjseek

Comment by wow powerleveling on 2008-04-08
Buy cheap WOW Power Leveling,sell wow gold.welcome to buy cheap wow gold-We can have WOW PowerLeveling,buy wow gold game, World Of Warcraft Gold,wow Gold, world of warcraft gold deal,Cheap WOW Gold. Welcome here to buy the professional World Of Warcraft Power Leveling service, World Of Warcraft PowerLeveling for Cheap Wow Powerleveling, WoW Power leveling Guide. The best of luckgoogle Best wishesAlcohol Tester purchasing center is a professional enterprise Breathalyser,Breathalyzer specializes in breath Gas Alarm consulting,Gas Detector through internet.Co Detector,Co Alarm always have been designed to alarm.

Post a Comment
Name
Email
(optional)
Comment
RatingUnhelpful Helpful
Security Image* (this is just to prevent spam submissions)
Security Image