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 shutdown function that checks to see if a redirect was just
I have a shutdown function registered using register_shutdown_function() that takes a long time to
I have a python script that I would like to add a Shutdown when
I'm trying to get a list of functions that have already run in the
PHP provides a mechanism to register a shutdown function: register_shutdown_function('shutdown_func'); The problem is that
I have a fun issue where during application shutdown, try / catch blocks are
I have a Java application which I want to shutdown 'nicely' when the user
Once the system is shutdown there will be message in syslog file. I have
Have just started converting an existing job tracking system into an ASP.NET MVC application.
I have a class that is a manager sort of class. One of it's

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.