Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Visitors logger cgi script

by Anonymous Monk
on Dec 24, 2004 at 13:06 UTC ( [id://417306]=perlquestion: print w/replies, xml ) Need Help??

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

Need 'visitors logger' cgi script for website, small, fast, without SSI. Log the
Date/time, Visitor IP, Page Visited, Host Name, Browser/OS, Referrer. There are many logger script, but most use SSI and have 2-3 scipts inside. Someone know useful script?

Replies are listed 'Best First'.
Re: Visitors logger cgi script
by brian_d_foy (Abbot) on Dec 24, 2004 at 23:09 UTC

    The best thing you can do is find a web host that gives you what you need without you needing to all sorts of tricks to get basic information that you should be able to see from the log files. Your service may have the log files available even though you don't know about it, though.

    You can get decent web hosting pretty cheaply: a lot cheaper than hacking up and supporting something to get around this problem. :)

    --
    brian d foy <bdfoy@cpan.org>
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Visitors logger cgi script
by dorward (Curate) on Dec 24, 2004 at 15:36 UTC

    Without using SSI there are two ways to do this.

    1. Have the script output an image

      Problems:

      • Requires the user to have a browser supporting images (and for them to be enabled).
      • Cannot capture the referrer (unless you throw JavaScript into the mix and dynamically generate the URI to the CGI script to include the referer as part of the query string.
    2. Disallow access to the real files and force users to access only the script. Use the query string to decide which file to load.

      Problems:

      • Really, really ugly URIs
      • You have to change all your links
      • Search engines tend to dislike sites consisting of one with with different query strings.

    Really, the best solution is probably going to be finding a better service provider.

      Well, first way(image)is acceptable. OK, without referrer. Here is some code I found, but it uses SSI. How to adjust it work with image?
      #!/usr/bin/perl # ####################################################### # Visitor Alert Script # # This script notifies you by email whenever your website is visited. # ####################################################### print "Content-type: text/html\n\n"; $sendto = 'you@yourdomain.com'; $mailprgm = '/usr/sbin/sendmail -t'; $page = $ENV{'DOCUMENT_NAME'}; $sitename = $ENV{'SERVER_NAME'}; $client = $ENV{'HTTP_USER_AGENT'}; $camefrom = $ENV{'HTTP_REFERER'}; $addrin = $ENV{'REMOTE_ADDR'}; @ip = split (/\./, $addrin); $binip = pack ("C4", @ip); $isp = gethostbyaddr ($binip, 2); { open (MAIL, "|$mailprgm") || die 'Could not open mail program'; print MAIL "To: $sendto\n"; print MAIL "Subject: Visitor Alert\n"; print MAIL "From: Visitor Alert\n"; print MAIL "\n"; print MAIL "Visitor Alert\n\n"; print MAIL "A visitor from: $isp ($addrin)\n\n"; print MAIL "OS and browser: $client\n\n"; print MAIL "Page name: $page\n\n"; print MAIL "Referrer: $camefrom\n\n"; print MAIL "Page visited: $sitename\n\n"; close (MAIL); } exit;
      Disallow access to the real files and force users to access only the script. Use the query string to decide which file to load.
        Problems:
      • Really, really ugly URIs

      Actually, the URIs do not have to be ugly if you use the path_info instead of the query string: http://myhost/index.html becomes http://myhost/a.cgi/index.html. You can even keep the URL same as before by using a ScriptAlias directive (which I suppose your host does not let you have, though).

Re: Visitors logger cgi script
by maa (Pilgrim) on Dec 24, 2004 at 13:27 UTC

    Isn't that what the server logs usually do? Can't you just use the raw stats or configure webalizer or something?

      My ISP NOT do this, never. No any stats, no raw, no any.

        Hi... ok, no stats and no SSI and that script you posted was scary (imaging getting an email each time a web-bot spidered your site... eek

        SSI probably wouldn't work anyway because almost every site that offers these disables the <!--#exec directive.

        If your site offers a cgi-bin for your site you could go for a full perl-based site ala perlmonks or slashdot.org. Your whole site would live under /cgi-bin/something.pl and you'd probably have an entry page that used a <meta> tag to do an http-refresh with the correct URL (since I assume you don't get URL re-writing available via .htaccess either.

        I find it extremely unlikely that they'll let you have perl scripts in any directory under your upload dir (public_html or www or whatever)... maybe you should consider changing your ISP? There are lots of good ones which are pretty inexpensive.

        Good luck...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://417306]
Approved by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-24 02:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found