Domain Name Registration

www.

AIT Press®

     → Latest Articles, Interviews and Press Releases
US Based Tech Support | Local: 1-910-321-1200 | Sales: 1-800-878-4084 | Support: 1-877-209-5184

Products & Services


 
INC500 webhosting search award Eco-Friendly Web Hosting awards Certified Microsoft Partner Buy Veteran AIT Website Award Nominate Your Site

AIT Facebook AIT Twitter
Viewing: Help Desk > Tutorials > PHP Tutorial > Chapter 7

PHP Tutorial [chapter 7]


How do I implement headers and footers using PHP?

PHP can be used to streamline your coding by setting up site-wide header and footer templates. Updates and maintenance are much easier to maintain with separate files dictating site look & feel.

Your first step to designing your headers and footers is to build your html header/footer. Your file can be named any of the following: .inc, .php3, .html, .htm, .txt The include will parse out whatever is within the "included" file.

Typically you would build your section, menuing system and/or body tag in the header. Footers might include contact or copyright information.

An example is below:

<html>
<head>
<title>Web page Title</title>
</head>
<body BGCOLOR="#FFFFFF">
<H1>Welcome!</H1>

Or you could create a more dynamic header that gets the title and page variables when the include is called. This would be similar to the following:

<html>
<head>
<title>$pagetitle</title>
</head>
<body BGCOLOR="#FFFFFF">

Calling the header and footer in the document

Now in the main body of your document call the header or footer you created.

<?PHP
include ('/includes/header.php3');
?>

Typically a programmer makes a folder "includes" for all of the various files they'll include throughout the website: i.e. headers, footers, database calls etc. This makes it easier to find all the files for editing and updating your site.

For more dynamic content

For more dynamic content pass your variable while you call the header/footer with your include command.

<?PHP
$title = 'Name of Site';include ('/includes/header.php3');
?>

     




Copyright © AIT, Inc. 2005-2011 / Policies / Facebook Twitter