How can the <base href=""> tag be utilized to control links within PHP includes?

When using PHP includes to include files from different directories, the links within those included files may not work correctly due to the relative path changing. To solve this issue, the <base href=""> tag can be utilized to set a base URL for all relative links within the included files. By setting the base URL to the root directory, all links will be resolved correctly regardless of the directory the included file is in.

&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;base href=&quot;http://example.com/&quot;&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;?php include &#039;header.php&#039;; ?&gt;
    &lt;p&gt;Main content of the page.&lt;/p&gt;
    &lt;?php include &#039;footer.php&#039;; ?&gt;
&lt;/body&gt;
&lt;/html&gt;