Magento – Redirect issue in magento

magento-1.7redirect

User dashboard where customer can login and can see all his information about ordered product and other information. In dashboard navigation menu, I added one more tab to redirect to external url. In controller, i am using $this->__redirect($url); bt is showing the error as :
"Cannot send headers; headers already sent"

I used a code in controller as :

    public function fooAction(){

$url = "http://example.com/bar/"; // this is external url 
$this->_redirect($url);
// Mage::app()->getResponse()->setRedirect($url);

}

It might be very easy but as I don't know, how to debug this in magento.

Thanks..

Best Answer

It may be because of extra white spaces after php closing tag (?>) in the file. This error also shown because of following points -

1.Any HTML output, including the DOCTYPE declaration or any HTML tag, including the head of the page

2.Extra whitespace before the opening PHP tag of the page, or outside the PHP tags of an include file

3.Using print() or echo before calling header() or session_start()

4.Using virtual() to include files

5.Using the byte-order mark (BOM) at the beginning of a page
Related Topic