Alex's Website
 

 

 


  

 

www AlexGomes.com

Home

 

About Me

PGP

My Blog

Resume

Domain Portfolio

SEO

GIMPS

Links

 

 

 

 

 

 

 

 

 

 

 

 

 

My Projects

 

Longhorn
Toolbar

ALD/PES

Current

(GIMPS)

 

Search
Engine

 

 

 

 

 

 

 

 

   

 

 

 

 
 
SSI Tutorial:

First Created:  Saturday April 24, 2004
Last updated: Sunday May 09, 2004 (First Draft)

Author: Copyright © 1998-2004 AlexGomes.com All Rights Reserved. Do not reproduce without permission.

 

Introduction
Filename
Server Check
Time
Include
Execute CGI
Echo
Conditional Statements
More

 

Introduction

SSI (Server Side Include) is a simple but powerful language. You can do pretty neat stuff with SSI without the added complexity of Perl or PHP. However if you want lot of functionality for your website you might want to consider Perl or PHP. Note: SSI is not SSL (Secure Server Language).


Filename

Before you get started remember to save your file with the extension of "shtml" (for most servers). Shtml files are same as html file except with the additional SSI statement. When the server sees a request to an shtml file it first parses the file for SSI statements. When it encounters the SSI statement it executes them and produces an html compatible output. The html compatible output replaces the SSI statement in the file and produces html compatible file for the viewer.

Client(Visitor) Server (Host)
1) GET  http://www.alexgomes.com

7) Receive http://www.alexgomes.com/index.shtml

2) Requested http://www.alexgomes.com/index.shtml

3) Parse index.shtml

4) Execute SSI statements in index.shtml

5) Replace executed SSI statements with the output of execution, in index.shtml

6) Send http://www.alexgomes.com/index.shtml

Note: All servers do not support SSI. Contact your server administrator for details.


 

Server Check

Copy paste the text below in a file and save it as "yourfile.shtml" . Then upload it to your server and view it with your browser.

Code

<html><head>
<title>Test</title></head
<body>
<!--#echo var="DATE_LOCAL" -->
</body>
</html>

The output should be some thing similar to this.

Output:    Saturday, 24-Apr-2004 22:51:39 EDT

If this worked your server is set up right.
If you get an error contact your server administrator.


 

Time

The time statement is the most popular use of SSI. You can use

Code  <!--#echo var="DATE_LOCAL" -->
Output Saturday, 24-Apr-2004 22:51:39 EDT

You can change the format of the time using

Code   <!--#config timefmt="%m/%d/%y" -->
Output: 04/24/04

Other options for time in UNIX are:

Code Purpose Of Code
%a abbreviated weekday name
%A full weekday name
%b abbreviated month name
%B full month name
%c locale's appropriate date and time representation
%C default date and time format
%d day of month - 01 to 31
%D date as %m/%d/%y
%e day of month - 1 to 31 (single digits are preceded by a blank)
%h abbreviated month name (alias for %b)
%H hour - 00 to 23
%I hour - 01 to 12
%j day of year - 001 to 366
%m month of year - 01 to 12
%M minute - 00 to 59
%n insert a newline character
%p string containing AM or PM
%r time as %I:%M:%S %p
%R time as %H:%M
%S second - 00 to 61
%t insert a tab character
%T time as %H:%M:%S
%U week number of year (Sunday is the first day of the week) - 00 to 53
%w day of week - Sunday=0
%W week number of year (Monday is the first day of the week) - 00 to 53
%x Country-specific date format
%X Country-specific time format
%y year within century - 00 to 99
%Y year as CCYY (4 digits)
%Z timezone name

 

Include

Include is the most useful SSI statements. You can include any file inside your shtml file. This helps when you are working with multiple webpages. You can have one file for all the multiple webpages, so when you change something  in the included file all your webpage will be updated automatically.

Code <!--#include file="top.txt"-->

You can include this statement on the top of all your webpages. When you want to change the headings of all the webpage you can just simply change "top.txt", oppose to changing every webpage.


 

Execute CGI

Another useful functionality of SSI is execution of server side scripts. If you need counter, tracker, banner, etc scripts which need to be executed when your page loads, this functionality is specially important. Your script can also produce an output  which will displayed in the place of your SSI statement.

Code <!--#exec cgi="counter.cgi"-->

 


 

Echo

The echo statement just displays the value of the "var". This example gives a link back to the referrer page.

Code <A HREF="<!--#echo var="HTTP_REFERER"-->">Referrer</A>

Other

 

Var Purpose Of Code
AUTH_TYPE client authorization method if any
CONTENT_LENGTH size of input posted from client
CONTENT_TYPE MIME type of content
DATE_GMT The current GMT (Greenwich, UK) can be formatted using #config
DATE_LOCAL current time/date, can be formatted using #config
DOCUMENT_NAME document name that was requested
DOCUMENT_URI URL of the document
LAST_MODIFIED document modified date, can be formatted using #config
PAGE_COUNT number of accesses to current document since server was brought on line
HTTP_REFERER URL of the document the client came from
REMOTE_ADDR Numeric IP address of the client
REMOTE_HOST domain name of the client (DNS option must be active on server)
REMOTE_USER ID of user, rarely ever found
REQUEST_METHOD HTTP method: GET OR POST
SERVER_NAME server hostname (i.e., www.alexgomes.com)
SERVER_PORT the port used by httpd (usually 80)
SERVER_PROTOCOL Which version of Httpd compliance
SERVER_SOFTWARE The name of the server software, i.e., apache 1.2.5
TOTAL_HITS total pages served by server since brought on line

 


 

Conditional Statements

If you are familiar with SSI so far, you should look at conditional statements. Remember to put <!--#endif--> statement after your last expression.

 

Code <!--#if expr="expression"-->
<!--#elif expr="expression"-->
<!--#else-->
<!--#endif-->

Example

Code <!--#if expr="${HTTP_USER_AGENT} = /MSIE [4-9]/"-->
You are using IE 4 or above<BR>
<!--#elif expr="${HTTP_USER_AGENT} = /Mozilla\/[4-9]/"-->
You are using Netscape 4 or above<BR>
<!--#else -->
You are using something other than IE 4+ or NS 4+<BR>
<!--#endif -->

 


 

More

If you want to explore more check out these links.

CGI Resource Index

 


 

 

 



Updates

Added My Blog

Domain Portfolio

Added GIMPS

SSI Tutorial

Google Search

Currently Working
on computer
security

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Tutorials

 

SSI

SEO

PHP
MySQL

Buffer
Overflow

LISP

NetBios

 

 

 

 

 

 

 

 

 

 

 

 


This site is best viewed with Internet Explorer 5 +
webmaster -at-  AlexGomes.com.

Copyright © 1998-2004 AlexGomes.com All Rights Reserved.