Random Text Generator Readme

Installation and configuration guide for Random Text Generator - display random quotes, tips, or text snippets on your website

Perl SSI Documentation

Table of Contents

Overview

Random Text Generator is a simple Perl script that displays a random text entry from a data file each time a page is loaded. It's perfect for adding dynamic content like quotes, tips, fortunes, or daily messages to your website.

The script works by:

  1. Reading entries from a plain text file
  2. Randomly selecting one entry
  3. Outputting the selected text to the webpage
Common Uses
  • Daily quotes or affirmations
  • Tips of the day
  • Random testimonials
  • Fortune cookie messages
  • Rotating taglines
Features
  • Simple text file format
  • No database required
  • Lightweight and fast
  • Easy to update content
  • Works with SSI

Requirements

Perl Perl 5.x or higher
Server Features CGI execution capability and SSI (Server Side Includes) support
File Access Ability to create/edit files in cgi-bin directory
Permissions Ability to set file permissions (chmod)
SSI Note: Your web server must have Server Side Includes enabled for this script to work embedded in HTML pages. Check with your hosting provider if SSI is available.

Installation

Step 1: Upload the Script

Upload rand_text.pl to your cgi-bin directory using FTP in ASCII mode.

Common Location: /cgi-bin/rand_text.pl

Step 2: Set Permissions

Make the script executable:

chmod 755 rand_text.pl

Step 3: Create Data Directory

Create a directory for your text data file:

mkdir /home/username/data
chmod 755 /home/username/data

Step 4: Verify Perl Path

Check the first line of rand_text.pl matches your server's Perl location:

#!/usr/bin/perl

Common alternatives: #!/usr/local/bin/perl or #!/usr/bin/perl5

Configuration Variables

Open rand_text.pl in a text editor and configure these variables:

$text_file

Variable $text_file = '/home/username/data/quotes.txt';
Description Full path to the text file containing your random entries. This file holds all the text snippets that will be randomly displayed.
Example $text_file = '/home/jsmith/data/quotes.txt';
$text_file = '/usr/local/www/data/tips.txt';

$delimiter

Variable $delimiter = '%%';
Description The separator used between entries in your text file. This must appear on its own line between each text entry.
Default %% (double percent signs)
Alternatives ###, ---, ==, or any unique string

Creating the Data File

Create a plain text file containing your entries, separated by the delimiter:

Format Example

The best time to plant a tree was 20 years ago. The second best time is now.
%%
Do not go where the path may lead, go instead where there is no path and leave a trail.
%%
Success is not final, failure is not fatal: it is the courage to continue that counts.
%%
The only way to do great work is to love what you do.
%%
Believe you can and you're halfway there.

Important Rules

  • Each entry can be multiple lines
  • The delimiter must appear on its own line
  • Don't put the delimiter after the last entry
  • Use plain text (no HTML unless you want it displayed)
  • Save the file in ASCII/text format

With HTML Formatting

You can include HTML tags in your entries:

<blockquote>
<p><strong>Quote of the Day:</strong></p>
<p>The best time to plant a tree was 20 years ago.</p>
<footer>— Chinese Proverb</footer>
</blockquote>
%%
<blockquote>
<p><strong>Quote of the Day:</strong></p>
<p>Do not go where the path may lead.</p>
<footer>— Ralph Waldo Emerson</footer>
</blockquote>

File Permissions

Set the data file permissions:

chmod 644 quotes.txt

Using the Script in Your Pages

With Server Side Includes (SSI)

Add this line to your HTML page where you want the random text to appear:

<!--#exec cmd="/cgi-bin/rand_text.pl"-->

Your HTML file must have SSI enabled. Common extensions:

  • .shtml
  • .shtm
  • .html (if SSI is enabled for .html files)

Complete HTML Example

<!DOCTYPE html>
<html>
<head>
    <title>My Website</title>
</head>
<body>
    <h1>Welcome to My Site</h1>

    <div class="quote-box">
        <!--#exec cmd="/cgi-bin/rand_text.pl"-->
    </div>

    <p>Rest of your page content...</p>
</body>
</html>

Direct CGI Access

You can also call the script directly in a browser to test it:

http://yoursite.com/cgi-bin/rand_text.pl
Tip: Reload the page multiple times to see different random entries displayed.

Real-World Examples

Daily Quotes

Display inspirational quotes on your homepage

<div class="daily-quote">
    <!--#exec cmd="/cgi-bin/rand_text.pl"-->
</div>
Tips & Tricks

Show random tips to users

<aside class="tip-box">
    <strong>Tip:</strong>
    <!--#exec cmd="/cgi-bin/rand_text.pl"-->
</aside>
Testimonials

Rotate customer testimonials

<section class="testimonial">
    <!--#exec cmd="/cgi-bin/rand_text.pl"-->
</section>
Fun Facts

Display random trivia or facts

<div class="fun-fact">
    <em>Did you know?</em>
    <!--#exec cmd="/cgi-bin/rand_text.pl"-->
</div>

Troubleshooting

Common Issues

Script Not Displaying / "500 Internal Server Error"

Possible Causes:

  • Incorrect file permissions (should be 755)
  • Wrong Perl path in shebang line
  • Uploaded in binary mode instead of ASCII
  • Incorrect path to data file

Solution: Check permissions, verify Perl path, re-upload in ASCII mode.

SSI Not Working / Shows Raw HTML Comment

Possible Causes:

  • SSI not enabled on your server
  • Wrong file extension (need .shtml or .shtm)
  • SSI not enabled for your directory

Solution: Contact your hosting provider about SSI support, rename file to .shtml

Same Text Always Shows

Possible Causes:

  • Only one entry in data file
  • Delimiter not on its own line
  • Incorrect delimiter in configuration

Solution: Check data file format and delimiter configuration.

Can't Find Data File Error

Solution: Check the $text_file path in the script. Use absolute path:

$text_file = '/home/username/data/quotes.txt';

Related Documentation

Random Text Examples

See live examples and use cases

Random Link Readme

Similar script for random URL redirects

All Readme Files

Browse all script documentation