gobbly2100 Posted March 2, 2007 Share Posted March 2, 2007 When I use this code like this: <?php include('includes/footer.html'); ?> It works fine but if I want to use it like this with a foward slash to make it work from the root: <?php include('/includes/footer.html'); ?> It just throws up a load of errors. Why is that? it is really annoying for when am trying to make pages within subfolders as I cannot link from the root so I have to put an includes folder in every sub folder if you know what I mean, I am sure there is a better way than this. Link to comment https://forums.phpfreaks.com/topic/40843-help-with-includes/ Share on other sites More sharing options...
magnetica Posted March 2, 2007 Share Posted March 2, 2007 Let me know if this works? Something like this? $_SERVER["DOCUMENT_ROOT"] . "/includes/footer.html"; Link to comment https://forums.phpfreaks.com/topic/40843-help-with-includes/#findComment-197749 Share on other sites More sharing options...
monk.e.boy Posted March 2, 2007 Share Posted March 2, 2007 To understand why this works: echo $_SERVER["DOCUMENT_ROOT"] . "/includes/footer.html"; monk.e.boy Link to comment https://forums.phpfreaks.com/topic/40843-help-with-includes/#findComment-197762 Share on other sites More sharing options...
gobbly2100 Posted March 2, 2007 Author Share Posted March 2, 2007 Sorry to be a noob but am really new to PHP, I have been a HTML man for God knows how long. How do I insert that code exactly? Link to comment https://forums.phpfreaks.com/topic/40843-help-with-includes/#findComment-197771 Share on other sites More sharing options...
ted_chou12 Posted March 4, 2007 Share Posted March 4, 2007 thats not really php, but anyways: when you add a slash at the front, it becomes a absolute path to the file, that is, the path from the root folder, therefore, this path can remain the same and link to the same file no matter where you place it, because it is in relate to the root directory, not the current file which is including that file. when you dont have a slash at the front, this becomes a relative path, so this would depend on which file that this path is pasted in, so it will not include the same file if you paste them in different dirctories. Hope that makes it clear. Ted Link to comment https://forums.phpfreaks.com/topic/40843-help-with-includes/#findComment-199069 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.