#!/usr/bin/perl #!/usr/local/bin/perl ############################### # Hot Links SQL 3 in.cgi # Created by Mike Ramirez # Nothing below here is configurable ############################### require './source/config.pl'; use CGI; use DBI; my $q = CGI->new; my $localtime = localtime(); $localtime =~ s/\d\d:\d\d:\d\d//; my $id = $q->param("id"); my $ip = $ENV{REMOTE_ADDR}; my $dbh = DBI->connect("DBI:mysql:$dbname;$dbhost", $dblogin, $dbpass) || print "Could not connect to database
"; my $id = $q->param("id"); my $in=0; my $out=0; if (!$id) { # If there is no id just forward to the index page print $q->redirect(-location=>$indexscript); } ## Check the database for an active ID my $sth = $dbh->prepare("SELECT * FROM links WHERE id = $id") || print "could not access database"; $sth->execute(); my $results = $sth->fetchrow_hashref; $sth->finish; if (!$results) { # If the id is not active forward to the index page print $q->redirect(-location=>$indexscript); } else { # Otherwise... # Get the current in count my $sth = $dbh->prepare("SELECT * FROM hitspop WHERE id = $id") || print "could not access database"; $sth->execute(); while (my $results = $sth->fetchrow_hashref) { $in = $results->{in}; $out = $results->{count}; } $sth->finish; # Check the hitlog to see if the ip has registered a hit already today. my $sth = $dbh->prepare("SELECT * FROM hitlog WHERE id = '$id' AND ip = '$ip'") || print "could not access database"; $sth->execute(); while (my $results = $sth->fetchrow_hashref) { $found_id = $results->{id}; } if (!$found_id) { # Add the entry to the hitlog my $sth = $dbh->prepare("INSERT INTO hitlog VALUES (\"$id\", \"$localtime\", \"$ip\")") || &error("Could not insert new row."); $sth->execute(); $sth->finish; # Update the poplist if (($in == 0) && ($out == 0)) { # If no hits in or out yet $in++; my $sth = $dbh->prepare("INSERT INTO hitspop VALUES (\"$id\", \"$out \", \"$in\")") || &error("Could not insert new row."); $sth->execute(); $sth->finish; } else { # If the site has at least one hit in or out already $in++; my $sth = $dbh->prepare("UPDATE hitspop SET `in` = $in WHERE id = $id") || print "could not access database"; $sth->execute(); $sth->finish; } } } $dbh->disconnect; # And we're done, send the visitor forward print $q->redirect(-location=>$indexscript);