#!/usr/bin/perl -w use strict; my $index = '../index.php'; # the main page to be edited my $index_backup = '../edit/backup.html'; # the main page backup my $url = 'http://www.mywebsite.com/edit/backup.html'; &back_up_file ($index, $index_backup); &redirect ($url); # makes an exact copy of the current index file - security incase something # were to go wrong when adding the news entry sub back_up_file { my ($index, $index_backup) = @_; # open the necessary files needed for reading and writing open (INDEX, "<$index") or die &show_error ("Unable to open $index: $!"); open(BACKUP, ">$index_backup") or die &show_error ("Unable to open $index_backup: $!"); # write the existing file into the backup while () { print BACKUP "$_"; } # close the files close (INDEX); close (BACKUP); } # redirects the user to the updated index page - or wherever specified sub redirect { use CGI qw(:cgi); my $url = $_[0]; my $q = CGI->new(); print $q->redirect( -url => $url ); } # shows the error returned inside of the browser - easier debuging sub show_error { print "Content-type: text/html\n\n"; print "This is the error:

$_[0]

"; exit(0); }