Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8722895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:30:25+00:00 2026-06-13T07:30:25+00:00

How can I get the first line of the servers’ HTTP response (Apache2 in

  • 0

How can I get the first line of the servers’ HTTP response (Apache2 in my case) for use in my PHP scripts? For example:

HTTP/1.1 200 OK
HTTP/1.1 404 Not Found
Etc.

Or better yet, get just the HTTP response code that my server sends to the client.

To my surprise, $_SERVER doesn’t have it. http_response_code() seems to only get the response code if it’s first been set by PHP. apache_response_headers() doesn’t seem to have it. get_headers() seems like it would require an extra step/connection (correct me if I’m wrong).

If I set ErrorDocument 403 /index.php in httpd.conf, I can use $_SERVER["REDIRECT_STATUS"] to get the response code from PHP, but is there another way?

EDIT:

Just to be clear, I find it odd that $_SERVER 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:30:26+00:00Added an answer on June 13, 2026 at 7:30 am

    UPDATE: NO IT’S NOT POSSIBLE Unless you proxy your own requests. Send your request to a Public facing URL and then redirect them to an internal variant and you get to see the headers in the process. But it’s not an easy feat and performance taxing also. Or you can write a Http Server extension and see where that takes you 🙂

    Example:

    • request comes to /page.html
    • you append ?proxy=true and forward to /page.html?proxy=true
    • attempt to load new URL internally forwarding the original request to you internal handler
    • check in your internal handling for all $_GET[‘proxy’] === ‘true’ requests come from local IP
    • if you have a proxy === true then handle this the usual way
    • /page.html gets data from /page.html?proxy=true
    • logs headers
    • forwards data back to original client
    • (not very easy and performance taxing if done wrong)

    FIRST ATTEMPTS AT ANSWERING

    http://php.net/manual/en/function.headers-list.php – may be this one?

    But this works for the headers you are about to send…

    register_shutdown_function(function(){
        // Headers are really sent here, do some comparison
        var_dump(headers_list());
    });
    

    .htaccess variant that directs all missing files to index.php.

    RewriteEngine on
    #If handler file is missing, pull index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* index.php [L,NC]
    

    Try this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why is the HTTP response code (or the first line of the HTTP response
How can I get first and last days of the current week? What I
I remember seen some code xaml where can get the first element (like an
I can get the the first row in a ListView item in .NET 3.5
How can I ignore first element and get rest of the elements? <ul> <li><a
I want to get 'second' in the following sample web address. http://www.mywebsite.com/first/sedond/third.html first can
I can use a GET request to submit HTML form data. If a HEAD
where can i get some references about SPL predefined constants like SELF_FIRST , CHILD_FIRST
Can get all triples with value null in specific field? All people with date_of_birth
We can get class Class object by 3 methods: MyClass.class obj.getClass Class.forName(className) I don't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.