Note that there are some explanatory texts on larger screens.

plurals
  1. POInclude vs Anchor paths
    primarykey
    data
    text
    <p>When I include a file like this: <code>include("/testsitedir/include/subdir/inc.php");</code> on a file named <code>this.php</code> within the <code>testsitedir</code> folder, I get the typical <code>failed to open stream: No such file or directory in ...\testsitedir\this.php</code> error. </p> <p>However, when I write a simple HTML anchor tag: <code>&lt;a href="/testsitedir/include/subdir/inc.php"&gt;Test Link&lt;/a&gt;</code> (URL is identical to the include's) The browser automatically resolves the URL for me and knows that the <code>/</code> indicates my site root. </p> <p>How, then, can I make my includes resolve the URL in the same fashion that the HTML anchor tag does?</p> <p>To get a better understanding, here is what I am trying to do. I have a header file located in a sub directory named <code>content</code> which is within the site's root directory. I am trying to figure out how to include the header on every file using the same URL. My approach is to just use an absolute URL to the header file. The reason this has become an issue is because I want to be able to readily change the site's root using a single <code>CONSTANT</code>. Also, the site's root directory will not always be the server's root directory. So when I want to put the site on a server in a sub directory <code>www.example.com/view/site/siteroot/</code> I would define a constant <code>SITE_ROOT</code> to be <code>/view/site/siteroot</code> and include any files using <code>include(SITE_ROOT."/includes/file.php);</code> But the include doesn't recognize the <code>/</code> forwardslash as a site root delimiter. I was going to use the actual site name but I don't want to enable <code>url_include</code> for security reasons. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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