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 3600712
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:31:48+00:00 2026-05-18T20:31:48+00:00

I have a shutdown function that checks to see if a redirect was just

  • 0

I have a shutdown function that checks to see if a redirect was just issued. From headers_list() I can get the headers sent and see the location header. My question is how would I figure out what http_response_code was used in the header() function. Headers list doesn’t have the response code.

Example code to play around with. I don’t use redirects in the example code, otherwise it would loop. Main thing is I would like to detect a 301 vs any other kind of redirect. This would be inside drupal (via drupal_goto using hook_exit); but the example code below shows the issue. I have no way of knowing what status number was passed to the browser via header().

<?php
register_shutdown_function('test');

if (mt_rand(0, 1)) {
  header('X-test: junk 1', TRUE, 201);
}
else {
  header('X-test: junk 0', TRUE, 202);
}

exit();


function test() {
  if ($location = test_headers_contain('X-test: ')) {
    // Would like to check the status code that was sent out
    echo $location . '<br>';
    $list = headers_list();
    $txt = str_replace('    ', '&nbsp;&nbsp;&nbsp;&nbsp;', nl2br(htmlentities(print_r($list, TRUE))));
    echo $txt;
  }
}

function test_headers_contain($text) {
  if (function_exists('headers_list')) {
    $list = headers_list();
    if (empty($list)) {
      return FALSE;
    }
    foreach ($list as $header) {
      $info = stristr($header, $text);
      if ($info !== FALSE) {
        return $info;
      }
    }
  }
  return FALSE;
}
?>

This code outputs this

X-test: junk 1
Array
(
    [0] => X-Powered-By: PHP/5.2.10
    [1] => X-test: junk 1
)
  • 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-05-18T20:31:49+00:00Added an answer on May 18, 2026 at 8:31 pm

    Revision 302033 added the function http_response_code in response to just the sort of issue you describe, but I’m not certain when it will be included in a release. It’s not in 5.3.4. If you have access, you could build a patched version of PHP with this function added. If not, you could request it of whoever on your host does have access.

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

Sidebar

Related Questions

I have a Delphi exe that is built with packages. The exe processes successfully
I have written a very simple socket server. It listens in post 63254. First
Couldn't find anything about this topic. I have a Windows TCP C++ server application
I am writing a Java app to shutdown my Linux box remotely. The desktop
I have an EJB app. which basically has to execute a SQL query when
I have a Qt 4.6.2 application, running on a Windows XP SP2 x64 system.
I am about to start implementing error handling into my framework and looking for
I'm working on a large (inherited) codebase in PHP, and the error Exception thrown
I am using nested master pages, which may or may not cause the problem
I'm writing a suite of programs for client PCs -- a Windows Service a

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.