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

Hi All

I am facing a small dilema with a little stat script I am writing to track visitors to a website. What I am doing is calling a perl file as an image in all of my HTML files and using that to log visitors. But, here is my problem; I am trying to log which page the image is called from, but whenever I use the ENV variables to find out the page called it obviously just give me the URL to the actual perl file serving the images..

Is there anyway to get around this?

Thanks!!

janitored by ybiC: Retitle from "Perl Dilema"

Replies are listed 'Best First'.
Re: Perl Dilema
by TomDLux (Vicar) on Sep 02, 2003 at 19:41 UTC

    Your CGI object has a referer attribute, which specifies what URL called the script URL.

    my $referer = new URI($q->referer);

    --
    TTTATCGGTCGTTATATAGATGTTTGCA

Re: Perl Dilema
by alienhuman (Pilgrim) on Sep 02, 2003 at 19:45 UTC

    Hey AM,

    What is it that you are trying to track? If its hits on a particular page--why not track the requests for that *.html page?

    Is it because you don't have access to the server logs? Help us understand your objective in the larger sense, and you'll get better responses.

    AH

Re: Perl Dilema
by bear0053 (Hermit) on Sep 02, 2003 at 19:24 UTC
    try to capture the referrer with javascript than pass that value into your perl script like this:
    <SCRIPT language=javascript> //<!--var x; x=""; x+="<a href='http://www.xyz.com'>"; x+="<img src='http://www.xyz.com/cgi-bin/tracker.cgi?m=CSP&page="; x+=escape(location.pathname)+"&ref="+escape(document.referrer)+"&ua="+ +escape(navigator.userAgent)+"&plat="; x+=escape(navigator.platform)+"&cooks="+escape(navigator.cookieEnabled +)+"&cpu="; x+=escape(navigator.cpuClass)+"&java="+escape(navigator.javaEnabled()) ++"'></a>"; document.write(x); //--> </script>
      You rock Bear.
Re: Perl Dilema
by hardburn (Abbot) on Sep 02, 2003 at 19:32 UTC

    If you don't like using JavaScript (I sure don't), then you can use SSIs. If your images are dynmically generated by the CGIs, then have another CGI which is called by an SSI exec. This CGI should have the same %ENV as the original page. This SSI then outputs the path to your current CGI, which generates the image just as it does now.

    If the image isn't dynamic, then you can simply SSI exec your current CGI and have it output the path.

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    Note: All code is untested, unless otherwise stated

Re: Perl Dilema
by dmitri (Priest) on Sep 02, 2003 at 19:25 UTC
    The wording of your question is somewhat strange, could you elaborate?

    JIC: did you try $ENV{HTTP_REFERER}?