PDA

View Full Version : The Basics of Server Side Includes


skrlin
August 20 '03, 04:46 PM
This is building off the example transio posted here (http://www.webdesignforums.net/showthread.php?s=&threadid=5519#post68869)

First thing you need to do is make sure that your host has support for Server Side Includes (SSI)

For this to work you need 3 files.
The first being page.shtml
page.shtml from transio's example
--------------------------------------------------
<!--#Include File="header.htm"-->
Here's the content of my page
<!--#Include File="footer.htm"-->
--------------------------------------------------

How this works:
When someone requests this file in a browser (ex: http://www.site.com/page.shtml ) the server will take out the include lines and in their place it will put the files being referred to.
If the file does not exist then you will see a very generic error inserted into the code in the include line's place [an error occurred while processing this directive]

The second file being header.htm
This file gets included by page.shtml and sets up a basic layout for everything to following it.
header.htm
--------------------------------------------------
<html>
<head><title></title></head>
<body>
<table>
<tr>
<td>
<a href="home.shtml">Home</a><br>
<a href="page.shtml">Page</a><br>
<a href="page2.shtml">Page2</a><br>
<a href="page3.shtml">Page3</a><br>
</td>
<td width="100%">
--------------------------------------------------


The final file being footer.htm
footer.htm basically closes out all the tags started in header.htm but it can be used for other things that are included at the bottom of all pages of a web site (ex: copyrights, etc.)
footer.htm
--------------------------------------------------
</td>
</tr>
</table>
</body>
</html>
--------------------------------------------------


I have also uploaded an image graphically explaining how this process works. Actual files will follow in subsequent replies.

skrlin
August 20 '03, 04:53 PM
Here's a link to the files on my server.

Reason being .shtml file extensions cannot be uploaded here more than likely for security reasons.

page.shtml (http://www.skrlin.com/other/ssi/page.shtml)
header.htm (http://www.skrlin.com/other/ssi/header.htm)
footer.htm (http://www.skrlin.com/other/ssi/footer.htm)

IMPORTANT: You must name this file with a .shtml extension or this will not work even if your host supports SSI

Wired
August 20 '03, 06:48 PM
You might want to redo the header file so that it goes across the top, as well as throw something in the footer, just so it's easier to look at. Right now, your header is on the left :)

smoseley
August 20 '03, 09:29 PM
If you're going to turn this into a tutorial, you might want to include the following in addition to SHTML:

ASP Includes
<!--# include file="controls.jsp" -->
PHP Includes:

<?php include("header.htm"); ?>

JSP Compiled Includes:
<%@page include="controls.jsp"%>
JSP Inline Includes:
<jsp:include file="header.jsp" />
JSP Inline Includes with Parameters:
<jsp:include file="header.jsp">
<param name="title" value="Web Design" />
<param name="keywords" value="Web, Design, Web Design" />
</jsp:include>

filburt1
August 20 '03, 09:30 PM
PHP is:

<?php include("/path/to/file.php"); ?>

smoseley
August 20 '03, 09:32 PM
LOL... fixed it, thx.

krazy
August 29 '03, 10:33 PM
when i do that, it says this:
Warning: main(/v4/nav.html): failed to open stream: No such file or directory in /home/virtual/site20/fst/var/www/html/v4/members/krazy.php on line 49


and line 49 is where it includes it, obviously. :confused: i dont get it.

filburt1
August 29 '03, 11:21 PM
It's the equivalent of a 404 (file not found) error. Make sure that you're including the file from the correct path (and name, of course).

krazy
August 30 '03, 12:48 AM
the file is there and it leads to the right place..

<?
php include("/v4/nav.html");
?>

isnt that right?

smoseley
August 30 '03, 01:37 AM
"/" at the beginning of a url defines a path relative to your web root (xyz.com).

krazy
August 30 '03, 03:09 AM
yes, exactly. thats where it is
first go to xyz.com
to the folder v4 and thats where the file is.

no solutions? :(

filburt1
August 30 '03, 12:34 PM
Originally posted by transio
"/" at the beginning of a url defines a path relative to your web root (xyz.com).

In PHP, it's relative to the file system, not your home directory.

smoseley
August 30 '03, 01:26 PM
I guess that's a good thing... that allows you to have your includes nested in your file system where they're not individually reachable from the web.

krazy
August 30 '03, 07:19 PM
it wont let me upload anywhere else but..
/var/www/html (here i can upload)

so where would that place be?

krazy
August 31 '03, 03:23 AM
Nevermind. Got it :)