Forum Moderators: phranque
Other server-side include methods such as PHP allow you to include files stored outside the document root, and thus the include files themselves are not available directly with an URL.
PCInk, will chmoding to 600 help me to avoid this problem. I mean will it be possible to retrieve my includes or not.
thx.
However, I tried to copy my site with mirror tools and good news is that it didn't download any includes and even folders that were not linked by any file.
So does that mean my includes and folders can be safe from someone who'll try to copy my site?
Another solution: use robots.txt to dissallow the spiders from seeing it, so it would never get listed in search engines and make the file name not guessable.
encyclo: you should be able to place the file in other folders. You just have to call it with the right path from your HTML. I have done this before.
I've tried to chmod 750, but it's also incorrect. Includes are not parsed, cause "others" have no "read" rights. I've left as it was 644 (owner: read-write, group: READ, others: READ) and it seems fine.
I've put includes in a separate folder and they seem to work well. I'll configure robots.txt as you said, so spiders don't index my include folder. Also, I thought that naming a file "top-secret" and showing in robots.txt that you don't want spiders to index it, could attract amateuer hackers to try to get in. So naming it like "folder" or putting includes in "cgi-bin" folder would be appropriate.
I'll also put index file in that folder and put some text in it like "You are not authorized to view this page" so it little confused readers.
what do you think
First of all, people will never learn the name of this file, unless you tell them. If you want to reduce the chance of them finding it by accident, you can give it a slightly less common name.
Is there some way to hide server side includes?
I hope I remember the details correctly:
If you use
[b]<!--#include [red]virtual[/red]="/footer.html" -->[/b], then the file path will be relative to your DOCUMENT_ROOT, ie. in the directory tree accessible by visitors. [b]<!--#include [blue]file[/blue]="/some/where/footer.html" -->[/b], then the file path will be absolute to your file system. In that case, you could place the include files in an otherwise inaccessible location. Of course, that's not a method that will make maintenance particularly easy... Needless to say that in either case, the contents (or processing results) of the included file will be visible to all visitors as part of the including file. That's why you use includes in the first place, after all.... ;)
Last question though.
When I put include in a folder, which is in root dir and try to access it from another folder, which is also in root dir, I type something like this:
<!--#include virtual="/includes/header.html"-->
But when I test it, it doesn't work. In all tutorials it's suggested to type forward slash at the beginning. But when I type it it doesn't work.
Somehow by accident I've discovered that typing:
<!--#include virtual="../includes/header.html"-->
works great. So is this correct or not? If it's correct then why everybody says to put forward slash at the beginning of the path?
If you use a virtual include, the first / is the document root of your site (absolute addressing). The ../ is the directory above your current directory (relative addressing). If you're one level down from the document root, then the two forms should be equivalent. If this isn't the case for your site, then the server doesn't agree with you about what the document root is. That may either be caused by a configuration problem, or by a misunderstanding on your side.
I have root directory. In root directory there are 2 folders. One named "folder" other "includes". In "folder" there's a HTML file, which calls include. In "include" folder, there's the actual include "footer.txt". So both: HTML file and include are in the same level, just different folders.
Now when in "HTML file" I put
<!--#include virtual="/include/footer.txt"-->
The / sign shows the root, I understand that. This should work, however when I try this thing on localhost it doesn't. But this:
<!--#include virtual="../include/footer.txt"-->
works fine. (Logically, both should work...)
Anyway, when I try to test on real server both work fine. So which method is better to use? Maybe latter one, because it works on my localhost and on real server.
What do you say...