) {
chop;
($raw,$hits,$url) = split(/\t/,$_);
if ($url eq $cookie) { $hits++; $gotit=1; }
push @urls,$url;
push @raws,$raw;
push @hits,$hits;
}
seek(F,0,0);
for $raw (@raws) {
$hits = shift @hits;
$url = shift @urls;
print F "$raw $hits $url\n";
}
print F "1 1 $cookie\n" unless $gotit;
}
# there is cookie.
if ( $cookie ) {
#print "Content-type: text/html\n\n";
print "Location: http://$cookie\n\n";
#print "$ENV{HTTP_COOKIE}";
}
# redirect URL #### non cookie ####
####################################
# browser does not support cookie, we need to open the tmp file
# created to redirect to new URL.
elsif ( (-e "$dir/$ip") && $action eq 'url' ) {
open(TMP,"$dir/$ip");
$URL = ;
close(TMP);
unlink("$dir/$ip");
print "Location: http://$URL\n\n";
} else {
print "Location: http://$default\n\n";
}
#
# generate a random img and url to go to, and set cookie no matter the browser
# supports cookie or not. if there is no HTTP_COOKIE defined, then create a
# file so that the action 'url' will be able to get the url.
} elsif ($action eq 'img') {
open(F,"$dir/$file") || die "Error opening file $dir/$file: $!\n";
while (chop($line = )) {
($url,$img,$freq,$sfreq) = split(/%%/,$line);
push(@imgs,"$img");
push(@urls,"$url");
#push(@freqs,$freq);
#push(@sfreqs,$sfreq);
for ($i=0; $i<$freq; $i++) {
push(@imgs,"$img");
push(@urls,"$url");
}
}
close(F);
# pick a random seed to randomly display banner
srand(time|$$);
$random = int(rand(scalar(@imgs)));
$cookie = $urls[$random];
$pic = "$imgs[$random]";
# record hits
if ( -e "$dir/$file.db" && open(F,"+<$dir/$file.db") ) {
my($raw,$hits,$url);
my(@raws,@hits,@urls);
my $gotit = 0;
while () {
chop ;
($raw,$hits,$url) = split(/\t/,$_);
if ($url eq $cookie) { $raw++; $gotit=1; }
push @urls,$url;
push @raws,$raw;
push @hits,$hits;
}
seek(F,0,0);
for $raw (@raws) {
$hits = shift @hits;
$url = shift @urls;
print F "$raw $hits $url\n";
}
print F "1 0 $cookie\n" unless $gotit;
}
# if there is no cookie, then we can write the URL, if there
# is cookie
# then we don't write to file since it is not necessary.
# write the URL so that when user clicks on the link, will
# bring to the exact page!
if (! $ENV{'HTTP_COOKIE'} && ! $ENV{HTTP_USER_AGENT} =~ /Mozilla/ ) {
open(TMP,">$dir/$ip") ||
die "Error opening file $dir/$ip: $!\n";
print TMP $cookie;
print TMP "\n$ENV{HTTP_USER_AGENT}";
close(TMP);
}
# set cookie
if (defined $domain) {
print "Set-Cookie: URL=$cookie; path=/; $domain\n";
} else {
print "Set-Cookie: URL=$cookie; path=/\n";
}
#print "Pragma: no-cache\n";
print "Content-type: image/gif\n\n";
# output image
open(IMG,"$dir/pics/$pic");
#while ( $img=
) { print $img; }
print
;
close(IMG);
# if your server supports cookies, then uncomment the two print
# statements. and comment the above three lines.
# also, you need to comment this too
# print "Content-type: image/gif\n\n";
#
# make sure that the browser displays the new image,
# Netscape version 2.*(1.*) do not do that.
#print "Pragma: no-cache\n";
#print "Location: http://$IMGURL/$pic\n\n";
} else {
print "Content-type: text/html\n\n";
print "Unknown action. Please check your url\n";
exit;
}