M
melkior_inactive
Guest
In my htaccess files tutorial I mentioned SSI and how to enable it.
I thought I could write a short article on SSI.
SSI or Server Side Includes are a way of adding dynamic content to otherwise static HTML files.
Again, we're talking about Apache servers here. Please note that.
Now, you might have seen static pages that display the time or similair things. This can be done via JavaScript but it can also be done by SSI.
I've told you how to enable SSI now let's look at the possibilities.
SSI directives look like HTML comments so if you don't have SSI on your site they just won't be displayed. But if you do, apache will search through the file, parse them, run them and display the output/results.
SSI always look like this:
SSI directives are always opened with <!--# and they are always closed with -->
If you want to output a value, you would use:
which is actually useless since it's content is static.
But let's say that you want to print out the date:
If you want to output when you last updated the file without actually keeping the track you could write something like this:
That would display the date of the last modification of the index.html file.
If you want to use the same header on all your html files and you want to avoid using frames you could do this:
You could do the same for the footer, or a menu.
Another side to SSI is running commands on the server. This is also the dangerous part. It's a great opportunity for hackers to run commands on your server. So you'll want to be careful.
There's also a difference if your apache server is running on Linux or on Windows since the commands aren't the same.
Let's say you want to display the output of the DIR command (the directory listing)
On Windows it would be:
But most servers are running Linux so that should be:
I'll give you some more examples tomorrow.
I thought I could write a short article on SSI.
SSI or Server Side Includes are a way of adding dynamic content to otherwise static HTML files.
Again, we're talking about Apache servers here. Please note that.
Now, you might have seen static pages that display the time or similair things. This can be done via JavaScript but it can also be done by SSI.
I've told you how to enable SSI now let's look at the possibilities.
SSI directives look like HTML comments so if you don't have SSI on your site they just won't be displayed. But if you do, apache will search through the file, parse them, run them and display the output/results.
SSI always look like this:
HTML:
<!--#tag variable=value-->
If you want to output a value, you would use:
HTML:
<!--#echo var="Hello"-->
But let's say that you want to print out the date:
HTML:
<!--#echo var="DATE_LOCAL"-->
If you want to output when you last updated the file without actually keeping the track you could write something like this:
HTML:
The file was last updated on: <!--#flastmod file="index.html"-->
If you want to use the same header on all your html files and you want to avoid using frames you could do this:
HTML:
<!--#include virtual="/header.html" -->
Another side to SSI is running commands on the server. This is also the dangerous part. It's a great opportunity for hackers to run commands on your server. So you'll want to be careful.
There's also a difference if your apache server is running on Linux or on Windows since the commands aren't the same.
Let's say you want to display the output of the DIR command (the directory listing)
On Windows it would be:
HTML:
<pre>
<!--#exec cmd="dir" -->
</pre>
But most servers are running Linux so that should be:
HTML:
<pre>
<!--#exec cmd="ls" -->
</pre>
I'll give you some more examples tomorrow.