View Source

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFDEV:Zend Proposal Zone Template}


[My E-mail Address|]

1.1 - 18 July 2006 - First revision

This is a simple suggestion for a modification to the _redirect member of Zend_Controller_Action.

I was attempting to write a simple logout procedure for some test code, and found that the logout redirect that used _redirect within a class, was failing with no evident output to redirect due to 'Headers already sent'

In the end it was whitespace at the end of my LogoutController that was causing the issue. However, the way I found it
was that using the PHP5 function headers_sent, I modified the code inside the library for Zend_Controller_Action to use the optional $file and $line variables to find where the header issue was being caused.

Perhaps this is something you might want to use in the _redirect function, since the output it gives upon failure can be used to help troubleshoot a very simple error which can plague the unwary coder for a fair while before discovering the issue, especially if the whitespace is hiding after the closing ?> tag in a Controller file as in my case.

* Zend_Controller_Action

* Redirect to another URL
* @param string $url
final protected function _redirect($url)
if (headers_sent($file, $line)) {
throw new Zend_Controller_Action_Exception('Cannot redirect because headers have already been sent on '.$file.', line '.$line);

// prevent header injections
$url = str_replace(array("\n", "\r"), '', $url);

// redirect
header("Location: $url");