|
Partners
|
|
| DATE_GMT | The current server date, in Greenwich mean time. Format using #config. |
| DATE_LOCAL | The current server date. Format using #config. |
| DOCUMENT_NAME | The file name of the current document. |
| DOCUMENT_URI | The virtual path of the current document. |
| LAST_MODIFIED | The last modified date of the document. Format using #config. |
| HTTP_REFERER | URL of the document the client derived from to get to current document. |
| REMOTE_ADDR | IP address of the visitor. |
| #flashmod | Command to display last modified date/time of a document or file on the server. Format using #config. |
| #fsize | Command to display file size of a document or file. Format using #config. |
To echo something using SSI, the syntax is:
<!--#echo var="VARIABLE HERE" -->
Lets see how to use these variables exactly.
To display the current server date and time, use either the "DATE_GMT" or "DATE_LOCAL" variable. In its simplest form:
<!--#echo var="DATE_LOCAL" -->
Output: Wednesday, 19-Jun-2013 17:42:21 MDT
Not bad eh for one simple line of code.
It's very useful at times to show the last modified date of a web page:
This document last modified: <!--#echo var="LAST_MODIFIED" -->
Output: This document last modified: Saturday, 04-Mar-2006 01:41:24 MST
You can also display the last modified date of any document or file on your server besides the present, by using another command called #flastmod instead of #echo:
greenday.mp3 last modified: <!--#flastmod file="grenday.mp3"--> Index page last modified: <!--#flastmod virtual="/index.html"-->
Sample output: greenday.mp3 last modified Thursday, 06-Jan-2005 05:35:27 EST.
This is also a commonly requested question and answer- how to display the user's IP address:
Your IP: <!--#echo var="REMOTE_ADDR" -->
Output: Your IP: 50.16.132.180
Finally, you can display the file size of any document on your server using #echo, by using a different command called #fsize.
This document's file size: <!--#fsize file="current.shtml" --> The file size of main index page: <!--#fsize virtual="/index.shtml" -->
Sample output: This document's file size: 8.4K
The interesting thing to note about using the output commands of SSI is that they can be embedded anywhere inside your HTML source, even in unexpected places to do interesting things. For example, you can use SSI echo to populate a JavaScript variable with the visitor's IP address, then continue to use JavaScript to react accordingly:
<script type="text/javascript">
var userIP="<!--#echo var="REMOTE_ADDR" -->"
if (userIP=="list of bad IPs to check")
alert("You are not allowed on this site.")
</script>
Another unconventional usage is to pass the current server time to the JavaScript Date object, then use JavaScript to display the current live time of your server:
var currentime="<!--#echo var="DATE_LOCAL" -->" var serverdate=new Date(currenttime) //rest of script
Here's a completed example.