What are some best practices for linking different pages with templates in PHP?

When linking different pages using templates in PHP, it is best practice to use relative paths to ensure that the links work correctly regardless of the current page's location within the directory structure. This helps maintain the portability and flexibility of the code. Additionally, using constants or variables to store the base URL can make it easier to update links in the future.

<?php
// Define a base URL constant
define('BASE_URL', 'http://example.com/');

// Link to another page using a relative path
echo '<a href="' . BASE_URL . 'page2.php">Page 2</a>';
?>