I want to write client request to a file with two things/information
- headers
- ip address
The code I'm testing on free hosting service.Code is
<?
$headers= apache_request_headers();
foreach ($headers as $header => value)
{
echo "4header: $ value </br >\n";
}
?>
Above, work for headers; but I'm confused what does apache_request_headers()
means its given as example in offical php website. Does it work for apache only?
If, the request header doesn't contain IP address I want to capture it as under
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
Merging the two, I want to write in single file and append it with time information for every request?. If time info is included as part of request...then its not required for new code.
Also, please suggest what the best way to capture such request, be it in separate php which is reading all the request to particular page or directory ; or put it inside the i.e index.html page. Thanks.
Thanks.