Solved

Outbound Link tracking

Posted on 2003-11-06
6
220 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:MAVERICK
6 Comments
 

Accepted Solution

by:
elsamman earned 125 total points
ID: 9702015
Sorry but what do you mean by an 'outbound link'?

...Sam
0
 
LVL 1

Author Comment

by:MAVERICK
ID: 9702198
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
0
 
LVL 8

Assisted Solution

by:jhurst
jhurst earned 125 total points
ID: 9726385
when I need to do this I do something like
 redirect.cgi?http://www.maverick.local/redirect.pl?url=http://www.exampledomain.com

my redirect cgi is :
#!/usr/bin/perl

$where2=$ENV{QUERY_STRING};
open(LOG,"">logFile");
print LOG <<EOT;
we transfered to: $where2
EOT
close(LOG);

print <<EOT;
Status: 302 re-direct
Location: $where2

EOT

exit;
0
 

Expert Comment

by:elsamman
ID: 9726662
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.



0
 
LVL 20

Expert Comment

by:jmcg
ID: 10089860
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
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question