Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Random" Content with SSI

SSI (Server Side Includes)

"Random" Content with SSI

by  cian  Posted    (Edited  )
Introduction
This guide will explain one simple method for displaying random content on a webpage 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
Code:
<!--#config timefmt="%S" -->
we can configure the time to seconds and include the content based on that second the page is called. In otherwords whatever second the page is called a certain file is included.


This example should explain it better:

[color blue]
Code:
<!--#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 -->
[/color]

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 alternativly you could base it on the second digit only by replacing the first digit with a 'period' such as:

[color blue]
Code:
<!--#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" -->
<!--#elif expr="$rand = /.6/" -->
<!--#include virtual="rand_content_6.txt" -->
<!--#elif expr="$rand = /.7/" -->
<!--#include virtual="rand_content_7.txt" -->
<!--#elif expr="$rand = /.8/" -->
<!--#include virtual="rand_content_8.txt" -->
<!--#elif expr="$rand = /.9/" -->
<!--#include virtual="rand_content_9.txt" -->
<!--#else -->
<!--#include virtual="fall_back_content.txt" -->
<!--#endif -->
[/color]

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!


Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top