Ray Ray - 1 year ago 109
Apache Configuration Question

In PHP < 5.4 is there any way to get a status response code you just set?

I know in php 5.4 there is a new function

, but in prior versions how would you get a response code you just set?

Similar to Is there any way to get the current HTTP response code from PHP?

I have this need:

//sometime earlier
header('HTTP/1.1 404 Not Found');

//sometime later, detect if error was set
$status = some_magic_way_to_find_status();

Does anyone have a way in php 5.3 or below to do this?

Answer Source

I don't think it's possible.

You could wrap the header() function:

function my_status_header($setHeader=null) {
    static $theHeader=null;
    //if we already set it, then return what we set before (can't set it twice anyway)
    if($theHeader) {return $theHeader;}
    $theHeader = $setHeader;
    header('HTTP/1.1 '.$setHeader);
    return $setHeader;

Or, of course, you could always upgrade to PHP5.4.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download