📜 ⬆️ ⬇️

Collecting statistics for viewing posts in LJ / LI

I saw a lot of scripts in different languages ​​that would tell me how to find out about their visitors. But they were all very strange and in places demanded things that I did not understand.
Due to the fact that all my life I wrote on Perl, I thought that it would be nice to understand how things are going with the solution of a similar problem.
The task itself is trivial and its solution is simple. Especially in PHP.
But I do not like PHP. And pearl never used for the web.

Therefore, for the evening, the following code was nakan:


')
#!/usr/bin/perl -w #    use strict; use warnings; use CGI::WebOut(1); use Mail::Mailer; #   my( $topic , $date , $ref , $flag , $tmp ); my( $query , $pair , $name , $value , $input ); my @pairs; my %input; my( $to_address , $subject , $mailer , $body , $from_address ); $date = `/bin/date "+%Y-%m-%d %H:%M"`; #         $to_address = 'info@microsoft.com'; #    $from_address = 'abuse@microsoft.com'; #    $flag = 0; #   if( $ENV{'REQUEST_METHOD'} eq 'GET' ){ #   $query=$ENV{'QUERY_STRING'}; } elsif( $ENV{'REQUEST_METHOD'} eq 'POST' ){ sysread( STDIN , $query , $ENV{'CONTENT_LENGTH'}); } $ref = $ENV{'HTTP_REFERER'}; #    @pairs = split( /&/ , $query ); #    foreach $pair ( @pairs ){ ( $name , $value ) = split( /=/ , $pair ); # 1=1 () if( defined( $name )){ #    if( !( defined( $value ))){ #    next; #   } } $value =~ tr/+/ /; #     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex())/eg; #  $value =~ s/<!--(.| )*-->//g; #   ( ? =) $input{$name} = $value; #   if( $name ne 'topic' ){ #   Topic? if( $flag == 0){ #     0 ? $flag = 0; #   ! } } if( $name eq 'topic' ){ # !    ! $topic = $value; #   $body .= "Topic: $topic\n"; #     $flag++; #     } #    ,    - , #     # if( $name eq 'mail' ){ # if( !(length( $value ))){ # $value = 'info@microsoft.com'; # } # } } if( !( defined( $flag ))){ ololo(); } #    (  ?       ! if( !( defined( $value ))){ ololo(); } #  ... if( $flag == 0 ){ ololo(); } #      if( defined( $ENV{'REMOTE_ADDR'} )){ $body .= "Remote address: $ENV{'REMOTE_ADDR'}\n"; #     ! } else{ $body .= "Remote address is unknown\n"; #  ... } if( defined( $ENV{'REMOTE_HOST'} )){ $body .= "Remote host: $ENV{'REMOTE_HOST'}\n"; #     } else{ $body .= "Remote host is unknown\n"; #       } if( defined( $ref )){ $body .= "Referer: $ref\n"; #    ! } else{ $body .= "Referer is unknown\n"; #    } $body .= "Date: $date\n"; #   $subject = "$topic at $date"; #    $mailer = Mail::Mailer->new(); #     $mailer->open({ From => $from_address, #  To => $to_address, #  Subject => $subject, #   }) or ololo(); # print "Can't open: $!\n"; # ,   ...    print $mailer $body; # ... $mailer->close(); sub ololo{ #    undef @pairs; undef %input; undef $topic; undef $date; undef $ref; undef $flag; undef $tmp; undef $query; undef $pair; undef $name; undef $value; undef $input; undef $to_address; undef $subject; undef $mailer; undef $body; undef $from_address; exit 0; } 


In .htaccess I wrote this:
Options +Includes +ExecCGI
In my LJ recording I am writing this kind of thing:
 <div style="display:none"> <img src="http://myserver.ru/lj.pl?topic=PLAZMOTRON" width=1> </div> 
<div style="display:none"> <img src="http://myserver.ru/lj.pl?topic=PLAZMOTRON" width=1> </div>

Where
  1. lj.pl - script name
  2. topic - the name of your topic that identifies an entry in LJ (In this case, PLAZMOTRON)


It seems like you need to specify a gif-dummy that will be given, but either I have a fairly modern browser (Firefox 3.6.17), or I didn’t understand something, lighting mana, but the script is quite working.
Hochma for the sake of it, you can blind the counter or something else useful.

This sample script is more useful to those who are just starting to work with the web using Perl (This is just about me).
The simplest way to work without monstrous-like modules of type Mason or CGI is shown, avoiding the 500th error and all kinds of print “Text / plain \ n \ n”;

Thank.

Source: https://habr.com/ru/post/122013/


All Articles