Looking good Melky![]()
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 -->HTML Code:<!--#tag variable=value-->
If you want to output a value, you would use:
which is actually useless since it's content is static.HTML Code:<!--#echo var="Hello"-->
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:HTML Code:<!--#echo var="DATE_LOCAL"-->
That would display the date of the last modification of the index.html file.HTML Code: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:
You could do the same for the footer, or a menu.HTML Code:<!--#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:
But most servers are running Linux so that should be:HTML Code:<pre> <!--#exec cmd="dir" --> </pre>
I'll give you some more examples tomorrow.HTML Code:<pre> <!--#exec cmd="ls" --> </pre>
Looking good Melky![]()
* Build a shopping cart for your business with eCommerce software UK
* BossCart.com can build you a.
Register your domain names at Velnet
::
Add Eco sites to The Green Directory free of charge.
Use LBS Free PHP Directory Script . Web Hosting Blog
Let's say you want to display the IP adress of the user browsing your site.
You can do that by writing this in your code:
You can also include the output of CGI scripts in your cgi-bin directory like this:HTML Code:<!--#echo var="REMOTE_ADDR"-->
That would execute the script called script.cgi located in your cgi-bin directory and it would print out the script's output in the page.HTML Code:<!--#exec cgi="/cgi-bin/script.cgi" -->
Usually used for visit counters or click counters.
If you want to link to the referrer page add this code:
And finally the conditionals or the IF statement.HTML Code:<a href="<!--#echo var="HTTP_REFERER"-->">Referrer page</a>
It is usually used to determine user's browser and serve different versions of the page customized for the browser.
It looks like this:
The first line of the code defines that the date should display the day of the week.HTML Code:<!--#config timefmt="%A"--> <!--#if expr="$date_gmt = Friday" --> Friday today, tomorrow's weekend. <!--#elif expr="($date_gmt = Saturday) || ($date_gmt = Sunday)" --> Weekend finally! <!--#else --> Another work day... <!--#endif -->
The rest of the lines compare the date to the set parameters and display text accordingly.
Well, that's about it. This was a short overview and a few examples included.
Hope you liked it.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks