On various pages throughout my PHP web site and in various nested directories I want to include a specific file at a path relative to the root.
What single command can I put on both of these pages...
http://www.example.com/pageone.php
http://www.example.com/somedirectory/pagetwo.php
...to include this page:
http://www.example.com/includes/analytics.php
This does not work:
<?php include('/includes/analytics.php'); ?>
Does it matter that this is hosted in IIS on Windows?
The absolutePath function works by beginning at the starting folder and moving up one level for each "../" in the relative path. Then it concatenates the changed starting folder with the relative path to produce the equivalent absolute path.
Relative links show the path to the file or refer to the file itself. A relative URL is useful within a site to transfer a user from point to point within the same domain. Absolute links are good when you want to send the user to a page that is outside of your server.
An absolute path refers to a file on the Internet using its full URL, e.g. "http://www.uvsc.edu/disted/php/webct/itr/index.php" A relative path assumes that the file is on the current server, e.g. "php/webct/itr/index. php".
You can just use include $_SERVER['DOCUMENT_ROOT'] . "/includes/analytics.php";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With