If you have the following file in the root directory
There are 3 folders under the HTML (root directory) images message styles
Html
--images
--a.jpg
--message
--liuyan.php
--styles
--students.css
--header.php
--footer.php
--index.php
Liuyan.php has the following code
Include (".. /header.php ");
Header.php has the following code
If I write
Then in the liuyan.php code will be in their own directory (message directory) to find images directory, and then find A.jpg. This is certainly not found, so the picture can not be found, the same, CSS file or URL to point to all wrong
Up.
If I write
Then you will go to the root directory of the images, you can find, no matter what level of directory you are, where the reference, so you can find.
Of course, if you have a header.php or footer.php in each directory, this can also solve the problem, but the complexity of the problem is the increase in order of magnitude.
At the same time, the written header.php must be written in the context of the root directory, that is, the latter. The meaning of include is to copy the code of the page you include into this PHP. Imagine if there is a src= ' images/' in the header. Code fragment, which is then used to refer to the code's sibling directory to find the images folder, which is not found and is wrong. And if there are some absolute path (relative to the root site of the absolute path) will not be asked, include or are going to the root directory under the images directory to find. That would be fine. You don't have to write headers repeatedly for each folder.
Oh, some of their own experience recorded a little. I also hope to be a bit of use to everyone. Path and coding can all be difficult in web programming. Oh ~