Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you are looking for a dynamic solution (in case you move the entire site to a subfolder or different domain), you can use PHP to get the absolute path of a file you are running (like your main php file) and then store that path in a constant or variable that you can use for all of your links.</p> <pre><code>if ( !isset($_SERVER['HTTPS']) ) { $domain = 'http://'.$_SERVER['HTTP_HOST']; } else { $domain = 'https://'.$_SERVER['HTTP_HOST']; }; $root = $domain.str_replace($_SERVER['DOCUMENT_ROOT'], '', dirname(__FILE__) ); </code></pre> <p>The first two lines just setup how the path will start, whether it should be http or https. The third line gets the full server path to the file that this code is in, removes the unnecessary parts (user/public_html) and stores it in the variable $root.</p> <p>You can then link your files this way:</p> <blockquote> <p>&lt;script src="&lt;?php echo $root; ?>/jquery.js">&lt;/script></p> </blockquote> <p>With this method, the site can be moved to any domain or subfolder, and you don't have to worry about breaking links.</p> <p>Edit: I just thought of an easier way to use this method. Rather than using absolute links, you could use your normal relative links along with this in the head of the document:</p> <pre><code>&lt;base href="&lt;?php echo $root; ?&gt;/"&gt; </code></pre> <p>This rewrites the base path for your relative links to the correct directory. Then this will work:</p> <pre><code>&lt;script src="jquery.js"&gt;&lt;/script&gt; </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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