Forum Moderators: phranque

Message Too Old, No Replies

Display/Log Client Request Headers

This is driving me mental, I'd appreciate any help

         

georgiecasey

5:20 pm on Jan 28, 2006 (gmt 0)

10+ Year Member



I know you can log basic HTTP headers like User-Agent and Referer to the Apache log file and you can also log any other client header *as long as you know the name*. Is there any way for apache to log the complete header sent by the client?

jdMorgan

8:39 pm on Jan 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can you give us more info on why you'd want to record all the request headers? That might help to suggest a solution, since there are several ways this could be done, but the most flexible solutions are relatively inefficient.

Jim

georgiecasey

9:14 pm on Jan 28, 2006 (gmt 0)

10+ Year Member



oh yeah, sorry.
Basically a site I want to access is off limits to normal web browsers, only mobile phones can access it. I want to emulate a mobile phone browser, so I need to know the headers a mobile sends to the server. So if I knew how to do this log all the headers, I would point my mobile at my site and check the logs.

jdMorgan

9:28 pm on Jan 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, if this is a one-time deal, then you could create a unique 'test' page with a php script that would dump all the server 'HTTP' environment variables back to the screen or to a file.

My concern was that if you wanted to continuously log all requests on a live server using a scripted approach, you could have ended up with a *very* slow server!

I've used a list of user-agents compared against the requesting user-agent to detect WAP clients with some success but that site was not intended for WAP users, so if I missed a few existing or new WAP clients, it was not critical. You may need something more sophisticated.

Jim

georgiecasey

9:55 pm on Jan 28, 2006 (gmt 0)

10+ Year Member



how do you dump the enviroment variables in php, do you know?thanks for your help

georgiecasey

10:10 pm on Jan 28, 2006 (gmt 0)

10+ Year Member



just found out the simple solution
a php script.
$headers = apache_request_headers();

foreach ($headers as $header => $value) {
echo "$header: $value <br />\n";
}

its that simple. numerous hours wasted!

jdMorgan

10:18 pm on Jan 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> its that simple. numerous hours wasted!

Ah, but never again, unless you forget. And your thread may help others in the future, too. ;)

Jim

extras

1:25 pm on Jan 29, 2006 (gmt 0)

10+ Year Member



This will show you environmental variables, too.
<? phpinfo();?>

I prefer shellscript (lighter, faster).

#!/bin/sh
echo
printenv¦sort