Search the site:
(New search engine!!)

SSI


This tutorial will cover some more SSI (Server Side Include) ground, in another tutorial I talked about including documents. This time we are going to take a look at the echo directive!

Before I start I should mention that not all servers can handle SSI and that SSI must be enabled on the server. Some servers also demand that you use the .shtml extension (i.e. mypage.shtml). Check with your admin of you can use SSI!

What echo basically does is displaying server information in the page.

A typical use is to display the date, like this:

<!--#echo var="DATE_LOCAL" -->

Just like when we included documents we need to put the SSI statement in a comment tag, or it will display exactly as above.

When used in a page it looks like this: Tuesday, 27-Jun-2017 16:33:12 MDT

SSI wouldn't be much fun if we were restricted to only displaying dates, here is a list of variables that you can use in your page:


AUTH_TYPE

Authorization method

CONTENT_LENGTH

Size of input posted by the client

CONTENT_TYPE

MIME type

DATE_GMT

The current GMT *

DATE_LOCAL

Time/date *

DOCUMENT_NAME

The name of the requested document

DOCUMENT_URI

Document URL

LAST_MODIFIED

Document modified date *

PAGE_COUNT

Number of page hits since the server was brought on line

HTTP_REFERER

URL where client came from

REMOTE_ADDR

The visitor's IP address.

REMOTE_HOST

The visitor's domain name. (DNS option must be set on server)

REMOTE_USER

ID of user (hardly ever works)

REQUEST_METHOD

HTTP method GET or POST

SERVER_NAME

Hostname (like www.yoursite.com)

SERVER_PORT

The port used by httpd (usually 80)

SERVER_PROTOCOL

Version of Httpd.

SERVER_SOFTWARE

The name and version of the server software.

TOTAL_HITS

Total server hits since it was brought on-line

Parameters market with a * can be formatted by using #config.

Here is an example of how #config is used:

<!--#config timefmt=”%y-%m-%d”-->

That would give you the Swedish date format yy/mm/dd, like this 04-12-31. If we change the code and used a capital “Y” we would get 2004-12-31 instead.

To format the date just put the #config statement before the #echo statement, like this:

<!--#config timefmt=”%y-%m-%d”-->
<!--#echo var="DATE_LOCAL" -->

Here is the "live" result using "%y": 17-06-27

SSI offers you a large number of formatting options for dates, here are all the format codes:

%a

Weekday name (short)

%A

Weekday name (full)

%b

Month name (short)

%B

Month name (full)

%c

Locale date and time format.

%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 get a space in front of it)

%h

Month name (short) same as %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

Minutes 00 to 59

%n

Insert new line character

%p

AM or PM

%r

Time as %I:%M:%S %p

%R

Time as %H:%M

%S

Seconds 00 to 61

%t

Insert a tab

%T

Time as %H:%M:%S

%U

Week number of year 00 to 53 (Sunday is first day)

%w

Day of week / Sunday=0

%W

Week number of year 00 to 53 (Monday is first day)

%x

Country specific date format

%X

Country specific time format

%y

Year two digits 00 to 99

%Y

Year as CCYY (4 digits)

%Z

Name of time zone

Do you want to learn how to include one document in another? Check out the Include tutorial!