Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm really wanting to do something along these lines...

When a user clicks on one of my links, it is logged to a file

I know how I could do this by linking them to a cgi script, that has a blank html page... the script would log the link, and the blank page would refresh in 1 second or so to the site they want to go to.

I was wondering if there would be a way to bypass that step. Load the CGI script, log the url, and redirect to the site, very fast, no middle page

Anyone have any ideas?

Replies are listed 'Best First'.
Re: Link logging?
by snowcrash (Friar) on Jul 13, 2001 at 10:07 UTC
    Just generate a redirection header, as documented in the CGI Manpage.

    #!/usr/bin/perl -w use strict; use CGI; my $query = new CGI; my $url = $query->param("whatever"); ### log the url to a file, database or whatever ### redirect user print $query->redirect(-uri=>$url, -nph=>1);

    hope to help

    update: oops, forgot to use CGI :)
    snowcrash //////
Re: Link logging?
by lestrrat (Deacon) on Jul 13, 2001 at 10:06 UTC

    Well, you are on the right track in that you think displaying the page with no content is kind of redundunt.

    First read the documentation for CGI.pm ( you *are* using CGI.pm, aren't you? ), and check out redirect()

    And if you want to know how that works, here's an explanation about the Location HTTP header

Re: Link logging?
by gremio (Acolyte) on Jul 13, 2001 at 10:07 UTC
    unfortunately if you have plain offsite links, the browser doesn't have to come back to your site at all to follow the link, so unless you redirect them to an onsite page first (which you can clearly track) you're theoretically out of luck.

    Except that you could make the link not really a link, but a javascript button that would simultaneously load some onsite cgi with a tracking parameter in one frame, say, while loading the intended target page in the other.

    That's where it stops being a perl question though, and I'm not sure that kind of practice would be looked upon as entirely ethical, so... YMMV.

    All the best,
    Grem

    mail q.gremio..q.@..q.speakeasy..q@.@.q.org.;
Re: Link logging?
by t'mo (Pilgrim) on Jul 13, 2001 at 16:55 UTC

    Some ideas you can use may be found at merlyn's web techniques articles, especially numbers 25 and 58.