March 28th, 2012, 11:00 PM
Problems using #include to include html doc
I am having trouble including code from an html document in another html document. I am currently using an Apache 2.2 testing server. Is it required for the included file to have an .shtml extension? Also, does the html code in the included file have to have html, head, and body tags or could it simply contain a <div>?
March 28th, 2012, 11:42 PM
Unless you configure the server to run .html files through the SSI processor, you need to use a .shtml extension.
Included files are not separate documents, so they should not contain such tags if the parent document contains them. If you're not sure if you're doing it right, check the "View Source" in your browser and use the HTML validator (which you should use anyway).
P.S. I would recommend that you use PHP includes instead of SSI, since PHP provides many more capabilities that you might like to use in the future.
March 28th, 2012, 11:59 PM
.shtml is not required; but proper server configuration is, whether .shtml is used or not. It is likely that your server doesn't allow server side includes.
You do not want to repeat the html declaration or head information. Your #include might be part of the head section though. Think of the resulting file as one contiguous html file.
If your server won't allow html SSI, don't despair. If you don't mind a .php file name, you can get the same effect using a couple of lines of very basic PHP.
March 29th, 2012, 01:35 AM
Hmm... True. Some servers might not have it enabled by default.
PHP files don't have to have .php extensions. However, I recommend hiding the file-name extensions of the pages with mod_rewrite (so it doesn't matter what they are).
March 29th, 2012, 09:13 AM
Thanks, I appreciate the replies. I will give that site and try and check back.
I am not using .php b/c the document is an .htm one, and I'm aware that I can change it to .php and use 'include()' but I prefer not to.
Not true, they do have to have a .php extension unless you configure the htaccess file accordingly.
Originally Posted by Kravvitz
March 29th, 2012, 04:54 PM
Yes, I know. I was implying that just like files that include SSI directives don't have to have a ".shtml" extension, files that contain PHP code don't have to have a ".php" extension.
A PHP file does not have to have any PHP code in it. You can use as little or as much PHP as you want.