Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Do you know where your variables are?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
#!/usr/bin/perl -w # showpic logger # Setup configuration # $home - filesystem path to append to images # $logfile - full path to the logfile you want to use # $ips - $ip addresses you want to ignore in the log # %entries - hash of labels => regexes for log my $home = '/my_path_to/public_html'; my $logfile = '/my_path_to/access_log'; my $ips = '127.0.0.1'; my %entries = ( 'home' => 'comatose/index.html$|comatose/$', 'resume' => 'resume' ); use strict; use Socket; # Open the pic or DIE! my $pic = $home . $ENV{PATH_INFO}; open PIC, "$pic" or die "Could not open $pic: $!"; # Get the size and MIME type my $type = ''; my $size = -s $pic; if ($pic =~ /gif$/) { $type = 'gif'; } elsif ($pic =~ /jpg$/) { $type = 'jpeg'; } else { die "Unknown image type"; } print "Content-type: image/$type\n"; print "Content-length: $size\n\n"; print while (<PIC>); # Now make the log entry my ($sec, $min, $hour, $mday, undef, $year, undef, undef) = localtime($^T); my $date = ('Sun','Mon','Tue','Wed','Thu','Fri', 'Sat')[(localtime)[6]] . ' '; $date .= ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug', 'Sep','Oct','Nov','Dec')[(localtime)[4]]; # Adjust timestamp to suit taste $year += 1900; foreach (($mday, $sec, $min, $hour)) { $_ = '0' . $_ if ($_ < 10); } $date .= " $mday $hour:$min:$sec " . $year; unless ($ENV{REMOTE_ADDR} =~ /$ips/) { my $hostname; $hostname = gethostbyaddr(inet_aton($ENV{REMOTE_ADDR}), AF_INET) or $hostname = $ENV{REMOTE_ADDR}; my $data = "$date $hostname"; open LOG, ">>$logfile" or last; flock LOG, 2; foreach (keys %entries) { print LOG "$data $_\n" if ($ENV{HTTP_REFERER} =~ /$entries{$_}/); } close LOG; }

In reply to Poor Man's Web Logger by comatose

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (13)
    As of 2014-04-17 14:43 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (450 votes), past polls