|
|
|
Server Side Includes (SSI) Tutorial
Part 2 - Scripts & Preset Commands
Introduction
In the last part I explained what SSI is and what it can be used for. In this part I will show you how using it with a script is useful and how you can include certian information into your page.
Scripts
One major use of SSI is to include the output from a script in your page. As I explained in the last part, the adverts a the bottom and side of this page are placed there using SSI. There is a very simple CGI script which, every time it is run, generates the code for an advert to place on the page.
This file is then called via a standard SSI call (like for any other file) with a slight change (although 'include virtual' usually also works):
<!--#exec cgi="/cgi-bin/clicktrade.cgi" -->
As well as for advertising rotation, SSI can be used with many other scripts, for example to display a textual visitor count on your page or to do an image or text rotation on a page of your site. It can even be used in conjunction with a content gathering script to seamlessly integrate it into your pages.
Preset Commands
SSI can also be used to display information on your page which is preset by the server. One of the major uses in the date and time command which is used as follows:
<!--#echo var="DATE_LOCAL"-->
which appears like this:
Friday, 12-Apr-2002 11:03:34 EDT
(this is not a live example, the true system time would be shown on a real ssi page)
This is the date and time on the server your site is hosted on. You can also display the date and time time in GMT using:
<!--#echo var="DATE_GMT"-->
The format the date and time appear as may not be what you want so you can format it using the 'Timeformat' command before the date command, for example:
<!--#config timefmt="%A, %d %B %Y"--><!--#echo var="DATE_LOCAL"-->
which will display:
Friday 12 April 2002
(again this is not a live example)
The time format is made up of some codes which you can separate as you want them to appear (like the comma I used above). Here is a list of some of the codes you can use:
Code | Function | Examples | %A | Full weekday name | Monday, Wednesday | %a | Abbreviated weekday name | Mon, Wed | %B | Full month name | January, December | %b | Abbreviated month name | Jan, Dec | %d | Number of day in month | 03, 1500
01/font> | %e | Number of day in month |
3, 15 | %H | Hour (1-24) | 05, 22 | %I | Hour (under 12) | 03, 11 | %j | Day number in year | 12, 245 | %m | Number of month | 1, 12 | %M | Minute | 12, 59 | %p | AM or PM | AM, PM | %n | New Line | |
%S | Second | 12, 57 | %t | Tab | | %y | 2 Digit Year | 99, 03 | %Y | 4 Digit Year | 1999, 2003 | %Z | Time Zone | EST, GMT |
As well as the time there are several other preset commands you can use inc
luding:
Document Name (the file's name):
<!--#echo var="DOCUMENT_NAME"-->
Doucument's URL (the part after the domain name)
<!--#echo var="DOCUMENT_URI"-->
Refering Page:
<!--#echo var="HTTP_REFERER"-->
Users IP Address:
<!--#echo var="REMOTE_ADDR"-->
There are some others as well, although these are the most useful.
What Next
Now you have learned the basics of using SSI you will probably find that you can't do without it! If you want to find out some of the other preset commands in SSI you can do a search on your favourite search engine.
©
1999 - 2019 FreeWebmasterHelp.com
| |