title: How to get Apache HTTP response code (or first line of server response) with PHP
body: <p>How can I get the first line of the servers' HTTP response (Apache2 in my case) for use in my PHP scripts? For example:</p>
  
  <pre><code>HTTP/1.1 200 OK
  HTTP/1.1 404 Not Found
  Etc.
  </code></pre>
  
  <p>Or better yet, get just the HTTP response code that my server sends to the client.</p>
  
  <p>To my surprise, <a href="http://php.net/manual/en/reserved.variables.server.php" rel="nofollow">$_SERVER</a> doesn't have it. <a href="http://www.php.net/manual/en/function.http-response-code.php" rel="nofollow">http_response_code()</a> seems to only get the response code if it's first been set by PHP. <a href="http://www.php.net/manual/en/function.apache-response-headers.php" rel="nofollow">apache_response_headers()</a> doesn't seem to have it. <a href="http://us.php.net/manual/en/function.get-headers.php" rel="nofollow">get_headers()</a> seems like it would require an extra step/connection (correct me if I'm wrong).</p>
  
  <p>If I set <code>ErrorDocument 403 /index.php</code> in httpd.conf, I can use <code>$_SERVER["REDIRECT_STATUS"]</code> to get the response code from PHP, but is there another way?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Just to be clear, I find it odd that <code>$_SERVER</code> returns almost every bit of data except for the first line of the response or the response code. Maybe it's a general limitation between the HTTP protocol/server technology/PHP? Maybe I shouldn't be trying to access this info in my PHP scripts?</p>