Jump to content

Help With Includes


gobbly2100

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.