Code provided here is for anyone to re-use, no attribution neccesary.
PHP can allow you to re-use code from php files, which provides you with a great way to template your sites. This can reduce your time administering the site, especially when dealing with code that is reused across multiple pages.
PHP has a function called 'include' that allows you to include files in other files. This enables you to have a light touch content management system without needed a full CMS or a database.
This trick can also be used to include other files, like functions, data and configuration files. Let me know how you use include files in your projects.
The below code shows you how it works. The below files will generate a base for building a site just like this one.
<?php
// PHP file for the header
$pageName = 'Index Page';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?=$pageName?></title>
</head>
<body>
<div class="footer">
<p>©<?php echo Date('Y'); ?> Copyright Your Name</p>
</div>
</body>
</html>
<?php
// PHP file for the index page
$pageName = 'Index Page';
include('header.php');
?>
<div>
<h1>Page title here</h1>
<p>Some text here</p>
</div>
<?php
include('footer.php');
?>
For more information on some of the techniques used in this project please see the following documents on the memopad pages.