Search code examples
zend-frameworkheader

Zend Framework setHttpResponseCode is not modifying the response header


I'm using zend framework ErrorController, but for some reason when an application error occurs, setHttpResponseCode should set it to 500, but when I

echo get_headers("my_url")

, I am still getting

Array ( [0] => HTTP/1.1 200)

Any idea how to modify the header to header ('HTTP/1.1 403 Forbidden'); event when I write this line just before get_headers() I still got the same 200 headers.


Solution

  • I think you need to call sendHeaders() after settHttpResponseCode().

    This is from the doc block in ZF:

    /**
     * Send all headers
     *
     * Sends any headers specified. If an {@link setHttpResponseCode() HTTP response code}
     * has been specified, it is sent with the first header.
     *
     * @return Zend_Controller_Response_Abstract
     */
    public function sendHeaders()