Use PHP to Simplify Headers and Footer on Your Web Page

By Winfield Ross, published May 07, 2008
Published Content: 34  Total Views: 3,150  Favorited By: 0 CPs
Rating: 3.0 of 5
Do you maintain your own web site? Do you have the same headers and footers on each page of your web site that you have to revise for every page if you want to make a change? That can be a lot of work and very time consuming.

There is a better way! Use PHP.

Don't stop reading if you are unfamiliar with PHP. Although PHP can get complicated, using PHP to simplify changes to headers or footers across all pages of your web site is quite easy. If you have a basic understanding of HTML then this use of PHP will be simple.

First, what is PHP? PHP is a scripting language developed to aid in web development and which can be embedded in HTML.

PHP was created in 1995 by Rasmus Lerdorf who developed a basic script to track how many people were viewing his online resume. He continued to add to the abilities of the script, the purpose of which was to help people maintain Personal Home Pages, thus the abbreviation PHP. As PHP has evolved, so has the description behind the name, which is now HyperText Preprocessor.

PHP is a server side script embedded in the HTML of the web page. While HTML is interpreted by the local browser, the PHP script is interpreted by the server and executed. The PHP code can do many tasks. The output is combined with the HTML with the result sent to the user's browser. If the user reviews the source code, they see the resultant HTML rather that the PHP script. They will not know that PHP was even used on the web site.

Luckily, you don't need to be a programmer or understand PHP to use this basic script on your web site. The only requirement is that your server supports PHP.

The picture to the left is an example of a PHP script. This can be the first portion of your web page prior to the HTML for the body of the web page. What this script does is tell the server to read and interpret the file "header3.php" before the rest of the page is interpreted by the local browser. In this case the file header3.php is a file with the HTML coding that you want for your header. The file header3.php is not different than any other HTML coding, but the extention "php" allows it to be treated differently.

Use PHP to Simplify Headers and Footer on Your Web Page

The code.

Credit: Winfield Ross

Copyright: Winfield Ross

Takeaways
  • Using PHP to simplify changes to headers or footers across all pages of your web site is quite easy.
Comments
Type in Your Comments Below - (1000 characters left)
Your name:

Submit your own content on this or any topic. Get started »
Most Commented On