RearViewMirror.org
Home
BITS
Old Musings
Scribbles
Projects
About
Contact Me
   November 22, 2008 Lillian. Nice name, that. (She was born December 1, 2006.)
 
 
  Random Quote Generator
This script was developed some time ago for a client of my wife's, with the intent of creating an automated "testimonial" presenter; each time the user of the intended page visited, they would see a different testimonial from one of the client's customers.

Rather than creating a simple hard-coded single-purpose script, I decided to put the extra few minutes into the job and created a generic script, which accepts a data file as a passed parameter and outputs a random line from the file. That way, testimonials (or fortunes, pithy sayings, whatever) can be maintained in a data file, and editing the data file changes the library of quotes. Since I had created a generic script, I figured I might as well make it available to anyone who wished to use it under the GPL.

The example here is from the SuSE 7.2 "fortunes" data file.


Before Xerox, five carbons were the maximum extension of anybody's
ego.

Download the SuSE 7.2 data file here.

Quote 1.0 (No longer available due to security issue)
Quote 1.1


 
 
  Small Change in Plans
The above solution works, and works well, but it isn't necessarily the best way to go. Currently, I'm using a PHP script that does the same job without requiring CGI permissions - in fact, the above example is the PHP version.

The PHP script is included below; use either version as best fits your host provider. Either version would work perfectly with Factory 55 <G>. It's a very slightly modified script (as in, the variable names have been changed to protect the guilty) from the PHP Developer's Cookbook.

<?php
   srand ((double)microtime()*1000000);
   $dat_file = file ("path/to/datafile");
   $dat = $dat_file[array_rand ($dat_file)];
   int $dat;
?>


 


  Security Focus
  CPAN
  FCC ID Search
  Network Calculators
  Useful Bookmarks
 
 
  The Register
  AlterSlash
  Google News
 
 
  Factory55
  Beland Internet Technology Services
  HiddenStar
  Jerry Pournelle
  Daynotes on a Budget