The post provided by @Teodor does not explain the differences, so hereās the answers.
SSI File vs Virtual
You use the file argument when the file that will be included is held within the same directory as the file that is calling for it. You can also use the file argument when the file is within a subdirectory of the directory containing the file that is calling for it.
You would use the virtual argument if the file you are calling for is located in a position requiring an address starting at the server root. Thatās an academic way of saying the file isnāt in the same directory as the page thatās calling it.
Maybe youāll set up a directory unto itself that contains all of your include files. This is a popular method of doing things. If so, then youāll use the virtual argument to attach the SSI command to the files. Just make a point of giving the command the path from the server root (the domain name). Like so:
<!--#include virtual="/directory/included.html" -->
That forward slash before the first directory is representative of the domain name (server root). By using that leading slash, the server will add the domain name to the front of the address for you.
Rule of Thumb
Use āfile=ā when the included file is within the same directory as the page that wants it. Use āvirtual=ā when it isnāt.
The Apache documentation recommends using āvirtualā in preference to āfileā.
Virtual example:
<!--#include virtual="/directory/included.html" -->
File example:
<!--#include file="footer.html" -->
PHP Include vs Require
The difference between include
and require
arises when the file being included cannot be found: include
will emit a warning ( E_WARNING
) and the script will continue, whereas require
will emit a fatal error ( E_COMPILE_ERROR
) and halt the script. If the file being included is critical to the rest of the script running correctly then you need to use require
.
SOURCES:
https://www.htmlgoodies.com/beyond/webmaster/article.php/3473341/SSI-The-Include-Command.htm