Forum Moderators: phranque

Message Too Old, No Replies

Run script for every request

.htaccess to the rescue?

         

bsterz

3:52 pm on Jul 1, 2005 (gmt 0)

10+ Year Member



Hi!

I would like to run a tracking script for every request made by a visitor (based on some simple criteria like if it's not a css file or an image etc).

Here is the real catch - I would like to capture the php session ID and current URI of the user so that I can do clickpath analysis. My preference would be to run a php file for every "page" request that does all of this for me, but I don't know how to set this up in my .htaccess file. I'm thinking that if I could tell apache to run a script and pass in some environment/session vars (like session and URI) I would be set.

I don't want to do this in a header or footer file as I want to track pdf's and HTM's as well and I don't want to do redirects or some such nonsense.

Any ideas? Am I skinning this particular cat in the wrong direction?

[edit - one note]
Perhaps I could set this up as an additional logging mechanism? Sort of like some folks pass their log entries thru a script instead of logging them directly - only I don't want to disturb my current logging, just perhaps add another logging method..

Thanks!

Bill

bsterz

7:46 pm on Jul 1, 2005 (gmt 0)

10+ Year Member



I'm looking at the CustomLog directive - does anyone have any experience using this directive in apache? I'm kinda willing to just try some stuff here :)

b

jdMorgan

2:27 am on Jul 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Other than rewriting all requests to a script, and having that script log the access and also serve the requested content -- which would be inefficient, I don't have any really useful suggestions.

But this is an interesting question, so I'm posting to bump it up on the active list...

Jim

sitz

10:11 pm on Jul 8, 2005 (gmt 0)

10+ Year Member



Some things to think about:

1) does it have to be based on PHP session ID, or will mod_unique_id [httpd.apache.org] give you what you need?

2) Apache 2.0.x supports logging cookies using mod_log_config [httpd.apache.org], which would allow you to log the PHPSESSID cookie contents.

Of course, you can always write your own module (or modify an existing one) to meet your needs, or even use mod_perl [perl.apache.org].

mcrosoft

4:42 am on Jul 9, 2005 (gmt 0)

10+ Year Member



send them via rewrite onto a php script which logs your need info and let the php script inlcude the original file to be served + deliver the right mime type

bsterz

7:47 pm on Jul 9, 2005 (gmt 0)

10+ Year Member



Well, as in all of my little adventures like this, once I realize that I CAN do it, I begun to wonder if I SHOULD do it.

I have decided to just parse the logs for this data.

But for completeness, here is what I did:

in httpd.conf include (or in the file itself):
CustomLog "¦/bin/log.cgi" extended

Then in log.cgi:
#!/usr/bin/perl

open(MYOUTFILE, ">>/var/log/out.txt");
while(<STDIN>){
my $line = $_;
chomp ($line);
print MYOUTFILE $line . "\n";
}

I guess I would do some setenvif stuff to filter out image requests, but I'm not sure I could ever get the session id in there.

Thanks for all the suggestions :)

Bill

[edited by: jdMorgan at 8:15 pm (utc) on July 11, 2005]
[edit reason] Disabled smily faces in code. [/edit]