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 |
Windows |
+ Microsoft IIS can do SSI as well, see the IIS help for details |
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.