Not really sure how easy this is to do but I will try and explain what I want...
I have links to six articles where at least one of them changes on a weekly basis. I currently have them saved as a library item so that I don't need to change individual pages - only thing is when I make a change I have to "PUT" most of my site as the list of articles appear on most of my pages - not a difficult task but I feel there must be a more efficient way of doing it.
I have played around with the CGI script from my host (below) and can't even get that to work when I have listed simple terms and was just trying to test it - does the random string need to be written in html or text? I've tried both and saved the page with an shtm extension and yet it still does not work. If I can get this script to work will it support links to the articles in the random text? - i.e. "rhubarbrhubarb - click here to learn more"
Does anyone know how to get this to work or have any other suggestions to my dilemma?!
Many thanks as ever...
------Place one random string per line in the box below.
Then add the following tag to the page you want the random HTML snippit to appear on:
<!--#exec cmd="cgi-bin/randhtml.cgi"-->
Make sure you save your page with an .shtm or .shtml extension!------
#!/usr/local/bin/perl
@articles = ( "Apples - click here to learn more", "Blueberries - click here to learn more", "Cherries - click here to learn more" );
@links = ( "http://mydomain.com/articles/apples.html", "http://mydomain.com/articles/blueberries.html", "http://mydomain.com/articles/cherries.html" );
$selected = int(rand(@articles));
print "Content-type: text/html\n\n";
print "<A HREF=$links[$selected]>$articles[$selected]</A>";
exit;
Use the following SSI command in your SHTML page:
<!--#include virtual="/cgi-bin/randhtml.cgi" -->
I tried to follow your advice but I don't think I am advanced enough yet (been trying to work out how to do it but failing...)
I think I may have come up with a solution though by including a simple server side include as per these instructions:
*****************************************
How to create a simple footer SSI using Dreamweaver
1 Create a new file in Dreamweaver.
2 Type in the information that you wish to appear on the bottom of your web pages. This might include your company address, or links to other sections of your site. For example:
Home ¦ Contact Us ¦ Gallery ¦ Orders
After typing the desired text, use the Property inspector to add links.
3 Select Window > HTML to open the HTML inspector. The source code for the example above looks like this:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<p align="center">
<font face="Geneva, Arial, Helvetica, sans-serif" size="2"><a href="/support/dreamweaver/ts/documents/home.htm">Home</a>
¦ <a href="/support/dreamweaver/ts/documents/mailto:myemail@address.com">Contact Us</a> ¦ <a href="/support/dreamweaver/ts/documents/gallery.htm">Gallery</a>
¦ <a href="orders.htm">Orders</a></font></p>
</body>
</html>
4 Highlight all the text displayed in black and delete it. The HTML inspector should contain only the information in red. It is especially important NOT to have <html>, <head> or <body> tags in the SSI, because this will cause the HTML on the page to become invalid once the SSI is inserted.
5 Choose File > Save to save the file. Name the file "footer.ssi" and save it inside the local root folder of your site.
6 Next, create a new HTML file and save the page inside the local root folder. Click the cursor on the page where you wish to insert the footer.
7 Select Insert > Server-Side Include. In the Select File dialog box, navigate to the footer.ssi file.
8 Save the HTML file with the .shtm or .shtml extension and close it. Using the Site Window, upload (put) the file to the remote server. Using your browser, go to the URL to view the page remotely from the server. Steps 6 - 8 can be repeated as often as desired, to add the footer information to multiple pages within a site.
*******************************************
This would mean I only have to update one page and not even touch my other web pages. I have two issues with this though
#1 - I don't really want to play about with the extensions as the search engines have only recently added my pages and I don't want to give them any trouble!
#2 - I have been testing it and it doesn't work. However when I do the following to check that my host supports SSI (which I know through their promotional material that they do) it doesn't work either - I am waiting to hear from them:
********************************
1 Create a new HTML page, and type the following in between the opening <body> and the closing </body> tags of the page:
<!--#echo var="DATE_LOCAL" -->
2 Save and name the page "test.shtm".
3 Upload the page to the remote server and view it using your browser.
4 If you see the current date displayed, your Web host supports SSI. If you do not see the date, your Web host does not support SSI.
***************************************
How bad an idea is it to change half my pages to shtm?
Does anyone have any advice on the above?
Cheers
Word of advice when inserting SSI in Dreamweaver make sure it is relative to the site root and not the folder - took me a while to work that one out...
Very happy!
#!/usr/bin/perl -wuse strict;
## EDIT THIS LINE ONLY!
my($random_file) = '/path/to/textfile.txt';
### Generic variables
my($temp,@temp);# Open the random file...
unless (open (RANDOM,"<$random_file")) {
# ... *OR* add error message to Apache error logfile
# & output a space character (" "). If you do not use
# Apache, or its error log, delete or comment out the
# following line.
warn "RANDOM_HTML: Text file '$random_file' is missing!\n";
print "Content-type: text/html\n\n \n";
exit;
}# Read file contents into list
@temp = <RANDOM>;
close (RANDOM);# Seed random number
srand(time()^($$+($$<<15)));# Pick a line, any line!
$temp = @temp;
$temp = $temp[int(rand($temp))];# Output line
print "Content-type: text/html\n\n";
print "$temp\n";# Fin!
exit;
Tested and works!
The only hard-coded information in the script is the location of the file that contains the random lines. The file itself is just a plain text file, and each line contains whatever you want. It's not as scalable as using a SQL database, but you should be able to stuff 'a lot' into the text file before your web host complains about memory usage.
While your text file could look something like this...
<a href="/page_one.shtml">Visit Page One!</a>
<a href="/page_two.shtml">Visit Page Two!</a>
...in the future, why not think bigger? What's a HTML page if you remove all the newlines? Hey, it's just one, long text string. So, after you've removed all the newlines from a half dozen pages and added them to the text file, add a link on your site to "random_page.shtml". In the page "random_page.shtml", all you put is...
<!--#exec cgi="/cgi-bin/random_html.pl" -->
...and suddenly your serving up whole random web pages!