Link to home
Start Free TrialLog in
Avatar of MAVERICK
MAVERICKFlag for United States of America

asked on

Outbound Link tracking

Hi,

I'm trying to find a script(preferably perl) that can track an outbound link and write the data to a MySQL DB.

Can anyone point me to any examples or starting points?

--Maverick
ASKER CERTIFIED SOLUTION
Avatar of elsamman
elsamman

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MAVERICK

ASKER

Hi Sam,

A link from my website to another website. An example is http://www.maverick.local/redirect.pl?url=http://www.exampledomain.com

I know how to do a redirect btw. I'm hoping someone has an example for logging the link access to a database.

--Maverick
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of elsamman
elsamman

OK.

This should do the trick.  I assume that

- Your user-id is xxx
- Your password is yyy
- You created a database called xxx_logging
- You went into mysql and created a table in that database with a statement such as:

use xxx_logging;
create table logging (url text);

Use this script to log the URL and then redirect to it (replace xxx and yyy)

#!/usr/bin/perl
use CGI;
my $cgi = new CGI;
my $url = $cgi->param('url');
use DBI;
my $dbh = DBI->connect("DBI:mysql:xxx_logging:localhost", 'xxx', 'yyy') or die 'Cannot open database';
my $stmt = "insert into log_table (url) values ('$url');";
my $sth = $dbh->prepare($stmt);
$sth->execute() or die "Cannot execute $stmt";

print $cgi->redirect($url);

Now in practice I would create a different user-id for the database than your actual UNIX ID since you don't want to embed that in a script.



Nothing has happened on this question in more than 8 weeks. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
split points between jhurst [50 pts] and elsamman [200 pts].

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer