How do I do full access logging including HTTP headers?

N

Nu

My webhost has sucky logging. So I'm looking for a perl or PHP script that
can do full logging of all the HTTP headers for each hit. I websearched for
hours and came up with nothing.
 
B

Brian Wakem

Nu said:
My webhost has sucky logging. So I'm looking for a perl or PHP script
that
can do full logging of all the HTTP headers for each hit. I websearched
for hours and came up with nothing.


This should get you started:

print "$_ -> $ENV{$_}\n" foreach keys %ENV;
 
J

Jürgen Exner

Nu said:
My webhost has sucky logging. So I'm looking for a perl or PHP
script that can do full logging of all the HTTP headers for each hit.
I websearched for hours and came up with nothing.

Doesn't surprise me that you didn't find anything.
Logging can only be done by the tool, that is performing the action. In this
case the web server is performing the action (= responding to HTTP
requests), therefore the web server must log its own action. There is no way
for an external tool to guess what the web server is or isn't doing.

jue
 
N

Nu

Thanks, any idea how to use .htaccess how to make it run whenever .htaccess
is called up?
 
J

John Bokma

Jürgen Exner said:
Doesn't surprise me that you didn't find anything.
Logging can only be done by the tool, that is performing the action.
In this case the web server is performing the action (= responding to
HTTP requests), therefore the web server must log its own action.
There is no way for an external tool to guess what the web server is
or isn't doing.

I know what you try to say, but it's not true how you wrote it. A simple
proxy that listens on port 80, and having your webserver on 8080 can do
that logging. It's an external tool ;-)

Also there are plenty of ways to plug in an external tool into Apache and
log anything you want.

The easiest is probably to extend the log format to include the headers
the OP wants.
 
N

Nu

I'm on a shared hosting and don't have root access and my host just said
their logs are the only ones they give.
 
J

John Bokma

Don't top post, if you don't know what top posting means, look it up in
the wikipedia.
I'm on a shared hosting and don't have root access and my host just
said their logs are the only ones they give.

What header(s) do you want to log, and for which request(s)?
 
J

Joe Smith

Nu said:
My webhost has sucky logging. So I'm looking for a perl or PHP script that
can do full logging of all the HTTP headers for each hit.

Brian has shown how to look at the headers which the web server
choses to put into the %ENV hash. If there are headers that you
are interested in but the web server throws them away by the
time your script is run, then you are out of luck. You _have_
to change the web server behavior to get at that data. For shared
web hosting, that usually means switching to a different webhost.
-Joe
 
N

Nu

John Bokma said:
Don't top post, if you don't know what top posting means, look it up in
the wikipedia.


What header(s) do you want to log, and for which request(s)?



I want to log all the headers of each visitor and then store it in a file
somewhere.
 
J

John Bokma

Nu said:
I want to log all the headers of each visitor and then store it in a
file somewhere.

Which additional headers are important to you? Since most should be
available in your access_log (referer, user agent, remote addr, request
path, method, status etc.).

I mean, of the additional headers (maybe I missed out a few):

HTTP_ACCEPT
HTTP_ACCEPT_CHARSET
HTTP_ACCEPT_ENCODING
HTTP_ACCEPT_LANGUAGE
HTTP_CONNECTION
HTTP_KEEP_ALIVE
REMOTE_PORT

you really need those? (just curious)
 
N

Nu

John Bokma said:
Which additional headers are important to you? Since most should be
available in your access_log (referer, user agent, remote addr, request
path, method, status etc.).

I mean, of the additional headers (maybe I missed out a few):

HTTP_ACCEPT
HTTP_ACCEPT_CHARSET
HTTP_ACCEPT_ENCODING
HTTP_ACCEPT_LANGUAGE
HTTP_CONNECTION
HTTP_KEEP_ALIVE
REMOTE_PORT

you really need those? (just curious)





Mostly IP, refer, user agent, and any spillings of an IP by a proxy. Maybe
browser.

Is it possible to use .htaccess to trigger a script that runs a log of this
so it will even log when they try to access an image file?
 
J

John Bokma

Nu said:
Mostly IP, refer, user agent, and any spillings of an IP by a proxy.
Maybe browser.

IP, referer, user agent (= browser) *should* be recorded in your
access_log. Proxy, see below.
Is it possible to use .htaccess to trigger a script that runs a log of
this so it will even log when they try to access an image file?

Yes, you can use mod_rewrite to route each request through a script and
log all additional information (proxy) that doesn't show up in your
access_log and have the script send back the requested object.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,049
Members
47,655
Latest member
eizareri

Latest Threads

Top