Assuming your web server is configured to allow it, use server-side includes. In PHP, this is done by using the
include(path)
directive.
Put your menu code in a single file, with all the HTML mark-up that you need. By convention, I give all included files an extension of
.inc
, to remind me that the file is a fragment that cannot stand on its own. Then place
<?php include("Menus.inc"); ?>
within your PHP page at the exact place where you want the fragment to be included. When the PHP page is retrieved, the first thing the web server will do is merge the include into the page and then perform any additional processing before sending it to the user. Your page should look something like this:
<html>
<head>
...
</head>
<body>
<?php include("Menus.inc"); ?>
<p>...</p>
</body>
</html>
To maintain the menus, just alter the
.inc
file; the pages will include the updated file automatically. There are a number of variations on how to to do this, and different functions, so you should probably do some research on the web to find exactly what you need.