Just building my new site, have a problem, how do link work inside the site ? For example I use a php include like so : <?php require_once("nav.php");?> but it does not work unless nav.php is in the same directory as the file which I am using the code in. So I want my code to be flexible so how can I modify this so if I copy the line on another page it will still find the nav.php file ? Oh and same goes if I want to move the file with the code in it.
Try to put all the main content pages in one directory, like the root. This way it will be like mysitedotcom/maincontent.php then put the navigation script in the same folder or in a sub folder. Link to it as You did <?php require_once("nav.php");?> or <?php require_once("/sub_folder/nav.php");?> you can copy this line to every content page and they will find the nav file because they are all in the same directory. So try to keep the main content in the same dir.
The nav.php is in the root, and content pages in various places, mostly in /html. Any way, it's still not too flexible. Can't I tell all the links to be relative to the root or some point on my site, not so relative one to another... ? How do I do this ?
In case you wish to have nav.php included in every file regardless of the current scripts location then use the DOCUMENT_ROOT variable like so: <?php require_once("$_SERVER[DOCUMENT_ROOT]/nav.php"); ?> Code (markup): Hope this helps!