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

Fellow Monks,
     I have recently been tasked with a problem that is quite puzzling to me. We are beta testing a piece of software that we have written for the windows platform. We want the ability to log to an Oracle DB as much information as we can on who, and the number of who, downloaded our product and when. My first impulse is to right a cgi to be the reciever of a hyperlink, recieve the user, log all the information possible, then meta redirect them to the actual software download. That's well and fine, except I have no idea how to grab any info from the customer. My question is this, is my way the most effective way, and if so how does one pull information such as the IP of a user via simple CGI/PERL? Any help will be much appreciated.
Tradez
"Never underestimate the predicability of stupidity"
- Bullet Tooth Tony, Snatch (2001)

Replies are listed 'Best First'.
Re: Meta Redirects and CGI
by screamingeagle (Curate) on Jan 27, 2002 at 14:36 UTC
    Another alternative would be to refer to the Environment variable hash %ENV which contains information such as the referring page, the ip address of the referrer,etc
    for example, the remote host can be obtained by :
    $remote_host = $ENV{'REMOTE_HOST'};
    or the referring url by :
    $referrer = $ENV{'HTTP_REFERER'};
    hope this helps... :)
Re: Meta Redirects and CGI
by LukeyBoy (Friar) on Jan 27, 2002 at 13:37 UTC
    Probably the easiest way to grab the IP address is:

    #!/usr/bin/perl -w
    use CGI;
    my $cgi = new CGI;
    my $ip = $cgi->remote_host();
    
    print "Content-Type: text/html\r\n\r\n";
    print "<html><body>Your IP address is $ip.</body></html>";
    
Re: Meta Redirects and CGI
by gt8073a (Hermit) on Jan 27, 2002 at 20:33 UTC

    We want the ability to log to an Oracle DB as much information as we can on who, and the number of who, downloaded our product and when

    This is not a pure perl suggestion, but I prefer letting web servers handle their own logging.
    If you are tracking downloads for marketing reasons ( build those who and when relationships! ), you may also want to watch how users navigate through your site to get to the actual download. Or, you may be interested in where visitors come from before they download.
    All of this is probably already logged in a file somewhere, but DBAs have to earn their keep like everyone else. Right?

    If you have an Apache server with mod_perl, you can use Apache::DBILogConfig. If you do not have Apache and mod_perl, I apologize because I can not help you.

    I am not saying using a script for this is neccessarily a bad thing, it might be all you need. And, mod_perl might be extreme overkill.

    Will perl for money
    JJ Knitis
    (901) 756-7693
    gt8073a@industrialmusic.com

      I do have mod_perl and am looking into your suggestion right now, thank you for your thought.
      Tradez
      "Never underestimate the predicability of stupidity"
      - Bullet Tooth Tony, Snatch (2001)
Re: Meta Redirects and CGI
by Parham (Friar) on Jan 27, 2002 at 19:35 UTC
    to answer your question, if you want to grab the ip of a user, look at $ENV{'REMOTE_ADDR'}. I'll take it a step further, if you want to change that IP into an address (or if $ENV{'REMOTE_HOST'} doesn't exist), try this:
    $ip = $ENV{'REMOTE_ADDR'}; @digits = split (/\./, $ip); $address = pack ("C4", @digits); $host = gethostbyaddr ($address, 2);
    other environmental variables you might find useful:

    $ENV{'HTTP_REFERER'} will contain where the user came from (a url)

    $ENV{'HTTP_USER_AGENT'} contains browser information of the user

    $ENV{'REQUEST_METHOD'} contains the request method (post, get) $ENV{'QUERY_STRING'} is what the query string was, everything after the '?' in the url
Re: Meta Redirects and CGI
by atcroft (Abbot) on Jan 27, 2002 at 23:02 UTC
    This is just an observation, but once they know the redirected target, they might be able to obtain other software if they have a reasonable guess as to the filename.

    You might consider having the CGI script pipe out the headers and content to initiate the download. You could call it something similar to /cgi-bin/logger.cgi/product.filename , so the browser would try to save it with the proper name. You would also have to be aware of the Content-Type and Content-length headers for product.filename.

    A little more work, perhaps, and off of your original question, but perhaps a little more likely not to be bypassed.