What are some best practices for including content in a PHP website with multiple pages?
When building a PHP website with multiple pages, it's important to include content in a way that is efficient and easy to manage. One common approach is to use PHP includes to separate out reusable content, such as headers, footers, and navigation menus, into separate files. This allows you to easily update content across multiple pages by making changes in just one file.
// header.php
<!DOCTYPE html>
<html>
<head>
<title>My Website</title>
</head>
<body>
<header>
<h1>Welcome to My Website</h1>
<nav>
<a href="index.php">Home</a>
<a href="about.php">About</a>
<a href="contact.php">Contact</a>
</nav>
</header>
```
```php
// footer.php
<footer>
<p>&copy; 2021 My Website</p>
</footer>
</body>
</html>
```
To include these files in your pages, you can use the `include` or `require` functions like so:
```php
// index.php
<?php include 'header.php'; ?>
<main>
<h2>Welcome to the Home Page</h2>
<p>This is the content of the home page.</p>
</main>
<?php include 'footer.php'; ?>