Installation and configuration guide for Random Text Generator - display random quotes, tips, or text snippets on your website
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:
| 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) |
Upload rand_text.pl to your cgi-bin directory using FTP in ASCII mode.
/cgi-bin/rand_text.pl
Make the script executable:
chmod 755 rand_text.pl
Create a directory for your text data file:
mkdir /home/username/data
chmod 755 /home/username/data
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
Open rand_text.pl in a text editor and configure these variables:
| 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';
|
| 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 |
Create a plain text file containing your entries, separated by the delimiter:
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.
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>
Set the data file permissions:
chmod 644 quotes.txt
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)<!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>
You can also call the script directly in a browser to test it:
http://yoursite.com/cgi-bin/rand_text.pl
Display inspirational quotes on your homepage
<div class="daily-quote">
<!--#exec cmd="/cgi-bin/rand_text.pl"-->
</div>
Show random tips to users
<aside class="tip-box">
<strong>Tip:</strong>
<!--#exec cmd="/cgi-bin/rand_text.pl"-->
</aside>
Rotate customer testimonials
<section class="testimonial">
<!--#exec cmd="/cgi-bin/rand_text.pl"-->
</section>
Display random trivia or facts
<div class="fun-fact">
<em>Did you know?</em>
<!--#exec cmd="/cgi-bin/rand_text.pl"-->
</div>
Possible Causes:
Solution: Check permissions, verify Perl path, re-upload in ASCII mode.
Possible Causes:
Solution: Contact your hosting provider about SSI support, rename file to .shtml
Possible Causes:
Solution: Check data file format and delimiter configuration.
Solution: Check the $text_file path in the script. Use absolute path:
$text_file = '/home/username/data/quotes.txt';
See live examples and use cases
Similar script for random URL redirects
Browse all script documentation