Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Visitors logger cgi script

by dorward (Curate)
on Dec 24, 2004 at 15:36 UTC ( #417317=note: print w/replies, xml ) Need Help??


in reply to Visitors logger cgi script

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.

Replies are listed 'Best First'.
Re^2: Visitors logger cgi script
by Anonymous Monk on Dec 24, 2004 at 15:52 UTC
    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;
use path_info for pretty URL
by Thilosophy (Curate) on Dec 28, 2004 at 11:27 UTC
    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).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2023-12-08 19:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (37 votes). Check out past polls.

    Notices?