What are the best practices for structuring PHP code to include headers, links, and sidebars without duplicating code in every page?

To avoid duplicating code in every page for headers, links, and sidebars in PHP, it is best to create separate PHP files for these elements and then include them in each page where needed using the `include` or `require` functions. This way, any changes to the headers, links, or sidebars can be made in one central location and will automatically be reflected on all pages that include these files.

```php
<?php
// header.php
echo "<header>This is the header</header>";

// sidebar.php
echo "<aside>This is the sidebar</aside>";

// links.php
echo "<a href='#'>Link 1</a>";
echo "<a href='#'>Link 2</a>";
```

To include these files in a page:

```php
<?php
include 'header.php';
include 'sidebar.php';
include 'links.php';
```

This approach helps in keeping the code DRY (Don't Repeat Yourself) and makes it easier to manage and update common elements across multiple pages.