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

I'm trying to figure out a way to track who came from where on my page.

Right now, I've got a script called through an image tag. The script doesnt need to display anything, altho I called it from the img tag in case I wanted to draw a smiley face or something random.
I digress.
I cant use env{'http_referer'} because, technically, the page that called the script was index.html. (the page with the <img..> tag in it.)
Can I find a way to use SSI calls to set a variable that I pass to the script? IE: <img src="http://www.phu.bar/cgi-bin/count.pl?referer=variablefromssicall ...>
? - I'm stumped - ?
_14k4
  • Comment on http_referer - can it be less anally retentive?

Replies are listed 'Best First'.
Re: http_referer - can it be less anally retentive?
by eg (Friar) on Dec 15, 2000 at 02:56 UTC

    This isn't exactly a perl question, is it?

    Well, I guess it could be if you use mod_perl and set up some handler to replace some variable in your .html or .shtml with the document's http_referer. But nevermind ...

    What you are clearly looking for is the SSI howto (http://httpd.apache.org/docs/howto/ssi.html) and the mod_include docs (http://httpd.apache.org/docs/mod/mod_include.html). The include variable will be something like ${HTTP_REFERER}

    Oh, and I'm assuming that you're using Apache or perhaps some close relative thereof.

    Not that I disagree with ichimunki in any way. Remember, some people turn off images and won't ever be counted by your script.

Re: http_referer - can it be less anally retentive?
by ichimunki (Priest) on Dec 15, 2000 at 02:55 UTC
    Why wouldn't you just look at your server logs to figure out who came from where? Barring that, you probably don't want to put a reference to a script into an <img> tag. You probably want to capture the environment variable in your main script for that page. That's the only reliable time the browser is going to set referrer to a URL from somewhere else. Of course, I see that you want to track this for a static HTML file, which brings you back to server logs. I've never heard a compelling reason to use SSI over simply writing a Perl script to replace index.html with index.pl.
      Server logs ... thats true. I didnt think of that. Must have slipped my mind. But as far as not calling a script through an img tag, I'm only doing that because when I originally had the script setup, doing things other than http_referer tracking, the server didnt have ssi setup. And it worked. Plain and simple. I forgot about people who shut off images... ugh.

      Replacing index.html with index.pl, is a solution. But only for that page. What if I would like to track every page within the site? But replacing index.html with index.pl, would definitally help in getting a 'true' http_referer value... altho, I am aware it can be faked, false, or just non-existant.

      Maybe I'll just replace index.html with index.pl and reference everything thats a link within the site to a pl script ... naaa .. thats not a good solution.

      Server logs it be. :) Thanks for the ideas/pointer in the right direction.

      _14k4 - webmaster@860.org (www.860.org www.poorheart.com)
Re: http_referer - can it be less anally retentive?
by epoptai (Curate) on Dec 15, 2000 at 06:30 UTC
    Javascript will do exactly what you want. The only caveats are that it only measures ppl with js enabled, and browser bugs cause a decent # of false referrers (meaning the 'referrer' may actually be the site they were at before they typed in your url, etc).
    <SCRIPT LANGUAGE="JavaScript"> <!--// var lt = unescape("%3c"); var gt = unescape("%3e"); var qt = unescape("%22"); var sq = unescape("%27"); document.write(lt + "IMG SRC=" + qt + "http://www.phu.bar/cgi-bin/"); document.write("count.pl?referrer="); document.write(escape(document.referrer)); document.writeln(+ qt + gt); //--> </SCRIPT>