Database design: keys, relationships and normalization
Design tables that avoid duplicated data: primary keys, foreign keys, one-to-many and many-to-many relationships.
Reuse headers, footers and settings instead of copying them.
If every page has its own copy of the menu, changing one link means editing every file.
Put shared parts in their own files:
site/
includes/header.php
includes/footer.php
index.php
about.php<?php // index.php
require __DIR__ . '/includes/header.php';
?>
<h1>Home</h1>
<?php require __DIR__ . '/includes/footer.php'; ?>require stops the page with a fatal error if the file is missing. Use it for things the page cannot work without.include only gives a warning and continues.require_once and include_once load a file only one time. Use them for files that define functions or classes.__DIR__ is the folder of the current file. It makes paths work from any page, in any folder.
include $_GET['page'] . '.php'; // DANGEROUSUse a fixed list of allowed names instead.
Design tables that avoid duplicated data: primary keys, foreign keys, one-to-many and many-to-many relationships.
A folder layout and a few habits that keep a growing PHP site tidy, secure and easy to maintain.