title: Capturing client request headers (complete) along with IP address information?
body: <p>I want to write client request to a file with two things/information</p>
  
  <ul>
  <li>headers</li>
  <li>ip address </li>
  </ul>
  
  <p>The code I'm testing on free hosting service.Code is</p>
  
  <pre><code>&lt;?
  $headers= apache_request_headers();
  foreach ($headers as $header =&gt; value)
  {
  echo "4header: $ value &lt;/br &gt;\n";
  }
  ?&gt;
  </code></pre>
  
  <p>Above, work for headers; but I'm confused what does <code>apache_request_headers()</code> means its given as example in offical php website. Does it work for apache only?</p>
  
  <p>If, the request header doesn't contain IP address I want to capture it as under</p>
  
  <pre><code>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'];
  }
  </code></pre>
  
  <p>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. </p>
  
  <p>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.</p>
  
  <p>Thanks.</p>