×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

SSI (Server Side Includes)

"Random" Content with SSI by cian
Posted: 9 Jun 03

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
<!--#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:


<!--#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 alternativly 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" -->
<!--#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 -->


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!



Back to Linux (server) FAQ Index
Back to Linux (server) Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close