Note that there are some explanatory texts on larger screens.

plurals
  1. POBase Location for PHP
    text
    copied!<p>I recently decided to incorporate PHP into my website, but I've never worked with it before so I'm not familiar with the functions...</p> <p>My problem is that I am using the include() method for my header and footer on each PHP page like this:</p> <pre><code>&lt;?php include('../php/header.php'); ?&gt; </code></pre> <p>This navigates from /public_html directory to the /php directory in the root of my website. To account for the different sub-directory levels that files may be located, at the top of each PHP page I add:</p> <pre><code>&lt;?php /* Path prefix so relative links work correctly */ $path = "../"; ?&gt; </code></pre> <p>and ../ could be replaced with ../../ for a file another sub-directory down and so on, and in the header and footer files, links are preceded like this:</p> <pre><code>&lt;a href="&lt;?php echo($path); ?&gt;index.php" title="Home"&gt;Home&lt;/a&gt; </code></pre> <p>and everything works fine like this...until I try to use it with wordpress which is located in a sub-directory on my website. Wordpress uses dynamic pages and so sometimes pages are located in a sub-directory lower than other pages and the links will fail to work with this method. In my old site design, I used the tag to set all link references to the root/public_html directory of my site. However, PHP is not affected by this tag. What I need is a method to set the the link references from the /public_html directory for my include() methods on the blog.</p> <p>Is there such a method or is there a better way to do what I am doing?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload