programming-examples/perl/CGI/Redirect a web page.pl

28 lines
831 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
use strict;
use warnings;
use CGI qw( :standard );
use Fcntl qw( :flock );
my @vars = qw( REMOTE_ADDR REMOTE_PORT REQUEST_URI QUERY_STRING );
my @stuff = @ENV{ @vars };
my $info = join( " | ", @stuff );
open( FILE, "+>>log.txt" ) or die( "Could not open log.txt: $!" );
flock( FILE, LOCK_EX ) or die( "Could not get exclusive lock: $!" );
print( FILE "$info\n\n" );
flock( FILE, LOCK_UN ) or die( "Could not unlock file: $!" );
close( FILE );
if ( $stuff[3] ne "" ) {
print( header( -Refresh=> '5; URL=http://www.java2s.com' ) );
print( start_html( "log.txt" ) );
print( p( i( "You will now be redirected to our home page." ) ) );
}
else {
print( header() );
print( start_html( "log.txt" ) );
print( h1( "Please add a \"?\" and your name to the URL.\n" ) );
}
print( end_html() );