Includes types

Would like to know why we have 4 types of includes to select from: SSI File, SSI Virtual, PHP Include, Require.

I have used PHP Include only so far and it does what I need. Just curious.

While we are at it, is there a method to ā€˜cascadeā€™ includes? So as to have an include, then another that combines the first include, then another include into one include?

In effect, like nesting DW template files.

Hey Dana,
Please check the following discussion:
SSI File vs PHP Includes it explains the differences :slight_smile:

1 Like

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

2 Likes