Redirect a web page : Page « CGI « Perl






Redirect a web page

    

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() ); 

   
    
    
    
  








Related examples in the same category

1.Track the number of times a web page has been accessed
2.Redirect page
3.Values Carried Between Pages
4.Page counter
5.Logs visitors to web site
6.Server push