Advanced HTML Guide

PHP Tips

Including common files in your page

A very useful technique for making it easier to create web sites is to have common elements such as menus, headers and footers in separate files which are then included into your main web pages. This has a number of advantages.
  1. Your site becomes easier to build as you can make much of each page up using standard building blocks rather than starting each page from scratch.
  2. You can easily update the common parts of your site by making a change to a single file rather than having to update every single page.
The syntax to include another file is very straight forward. e.g. the below snippet will include a file directly into the current page. This is what I use to include the standard menu that you see on the left of each page on
Below is a simplified version of what my contains. Each time I update the menu all the pages on this site are automatically updated.
<a href="/">
  <img src="/advancedhtml.gif">

 <font size="-1" face="arial">
  <a href="/advancedhtml.htm">Advanced HTML</a><br>
  <a href="/tables.htm">Tables</a><br>
  <a href="/frame.htm">Frames</a><br>
  <a href="/password.htm">Passwords</a><br>
  <a href="/colours.htm">HTML Colours</a><br>
  <a href="/webspace.htm">Buying Webspace</a><br>

For this to work you just need to be in the same directory as your .html or .php files.

If you are going to be including a menu from many different directories then it may be better to include a full path to the menu file. If you are using an Apache web server you may be able to do this by using the DOCUMENT_ROOT property.

include_once($_SERVER['DOCUMENT_ROOT'] . '/');

Keeping your copyright footer up to date automatically

Imagine that in 2007 you create a webpage and you add a copyright footer. Time passes and we reach 2008. The problem is that your copyright footer is now out of date. There is an easy way to sort this out. Use some simple PHP to keep the current year up to date.
<font size="-2" face="arial">

$today = getdate();
print "Copyright &copy; 2007 - ".$today["year"];

If the current year is 2024 then the output will be 'Copyright © 1997 - 2024'.

Advanced  HTML
Privacy Policy
Advanced HTML Home
Copyright © 1997 - 2024
Hosted by IONOS