#!/usr/bin/perl -w use CGI qw(:cgi); # by James Thornton # http://www.jamesthornton.com/code/redir.txt # Save file as: redir # -- it looks better than redir.pl (see below) # Encode outbound hyperlinks as: # whatever.com # If you get an error the first time you use this program, check the # user and group of the created database, and if it isn't the same # user and group used for your webserver, change it. # Use http://www.jamesthornton.com/code/redir_out.pl # to output saved data to a terminal # get the url that the user is going to $url = param{'url'}; # don't monitor click-throughs for these hosts $localhosts = "yourdomain.com|10.0.0|192.168.1"; # this is the database that will hold the data (it # will automatically be created for you) $db = "/path/to/your/db/redirect"; # don't save click-through data if the user is coming from one of our hosts if ( ($ENV{REMOTE_HOST} !~ /$localhosts/) || ($ENV{REMOTE_IP} !~ /$localhosts/) ) { dbmopen(%LIST, "$db", 0644) or die "Can't open $db."; # create a db entry and/or increment the number of click-throughs foreach ($first .. $last) { ++$LIST{$url}; } dbmclose(%LIST); } # now that we have the info we need, send the user where they want to go print redirect( -URL => $url );