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?
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:
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”.
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 .