Server Side Includes

Try online Examples

There is another, quite powerful way to generate web pages: Server Side Includes.
Basically you have a normal web page, such as this one, but parts of it (or in this case one part) are generated by one or several scripts.
A SSI page could look like this:

	<html>
	<head>
	        <title>Example: Server Side Include</title>
	</head>

	Here, for example, we have a counter:<BR>
	<!--#include virtual="/cgi-bin/ssi.e.txt"-->

	<p>
	(....)
	</body>
	</html>

And the ssi.e.txt script is as follows:

sub main

	// This should lock the file as in the web counter example,
	// but we're keeping things simple here.
	// For locking, check the Web counter example.
	// The advantage of using SSI is that here we're outputing text
	// and not a graphic. In some cases, it may well be more
	// flexible.

	print("Content-type: text/html\n\n")
	n = loadFile("c:/temp/aptilis/ssihits.dat")
	saveFile("c:/temp/aptilis/ssihits.dat", n + 1)
	print("This is another way to generate a hit counter: <FONT color=\"#FF0000\"><B>", int(n)$, "</B></FONT>")

end main

Now, in order to get this to work, you need to ensure the following:
- Your file (such as this page) must usually have a different extension than '.html'. On this server, it's '.shtml'.
- You must put your script in the CGI directory and make it runnable.

Unix

+ This means running the command chmod 755 name_of_your_script.e.txt
+ You must indicate where the interpreter for your file is.
This means that you must specify aptilis.exe as an interpreter for yur script.
To do that, you use the #! syntax on the first line of your script, example:
#!/home/httpserver/cgi-bin/aptilis.exe
See how to make a script runnable in more details.

Windows

+ Microsoft IIS can do SSI as well, see the IIS help for details
+ If you are using Apache, the configuration is the same as for Unix systems, except that you don't have to chmod the script and the first line of the script should look something like
#!c:\apache\www\cgi-bin\aptilis.exe
+ When using OmniHTTPd make sure that Process Server Side Includes (SSI) is enabled (you'll find it under Configuration -> Web Server Global Settings -> Advanced). Then change to the tab External and add : Virtual: .apt (or e.txt) / Actual: c:\aptilis\bin\aptilis.exe (if your aptilis.exe resides in this location)

This is because whatever you're invoking is supposed to come from the same server as the page.
- Your server must be configured to support SSI. I found this to be a bit tricky myself. The syntax used here 'include virtual' may also be different on your server. On my Apache server I had to add this to the access conf.file:

	<DIRECTORY /home/*/html>
	Options +Includes
	AllowOverride None
	order allow,deny
	allow from all
	</DIRECTORY>

That would enable SSI in the html directories of my users.