Home     SSI Lab     CSS Templates     CSS     Htaccess     Web Design     XHTML

X-SSI Lab

graphic-img   



Random Content with SSI

Bookmark with StumbleUpon
del.icio.us
Digg it
reddit
Furl
Spurl
ma.gnolia
Yahoo MyWeb
Windows Live
Sponsors

Introduction

This guide will explain one simple method for displaying random content on a web page using SSI.


The most obvious way to do this is to make use of SSI's ability to configure the time format. By using the code <!--#config timefmt="%S" --> we can configure the time to seconds and include the content based on that second the page is called. In other words whatever second the page is called a certain file is included.

This example should explain it better:

<!--#config timefmt="%S" -->
<!--#set var="rand" value="$DATE_LOCAL" -->
<!--#if expr="$rand = /00/" -->
<!--#include virtual="rand_content_0.txt" -->
<!--#elif expr="$rand = /01/" -->
<!--#include virtual="rand_content_1.txt" -->
<!--#elif expr="$rand = /02/" -->
<!--#include virtual="rand_content_2.txt" -->
<!--#elif expr="$rand = /03/" -->
<!--#include virtual="rand_content_3.txt" -->
<!--#elif expr="$rand = /04/" -->
<!--#include virtual="rand_content_4.txt" -->
<!--#elif expr="$rand = /05/" -->
<!--#include virtual="rand_content_5.txt" -->
<!--#else -->
<!--#include virtual="fall_back_content.txt" -->
<!--#endif -->

What this basically does is format the time to seconds and then includes the contents based on the second the page is requested. This is obviously a shortened example, I only coded it for the first 6 seconds but you could code it for the full 60 seconds or alternatively you could base it on the second digit only by replacing the first digit with a 'period' such as:

<!--#config timefmt="%S" -->
<!--#set var="rand" value="$DATE_LOCAL" -->
<!--#if expr="$rand = /.0/" -->
<!--#include virtual="rand_content_0.txt" -->
<!--#elif expr="$rand = /.1/" -->
<!--#include virtual="rand_content_1.txt" -->
<!--#elif expr="$rand = /.2/" -->
<!--#include virtual="rand_content_2.txt" -->
<!--#elif expr="$rand = /.3/" -->
<!--#include virtual="rand_content_3.txt" -->
<!--#elif expr="$rand = /.4/" -->
<!--#include virtual="rand_content_4.txt" -->
<!--#elif expr="$rand = /.5/" -->
<!--#include virtual="rand_content_5.txt" -->
.
.
.
<!--#else -->
<!--#include virtual="fall_back_content.txt" -->
<!--#endif -->

In this case you only need to code the expressions up to .9 seconds.

This is not exactly 'random' but the best we can do!