Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
snapper

Cannot Modify Header Information Error

Recommended Posts

When a user clicks a button in my application, it is supposed to reroute them to a certain page in my application, but instead I get the following error message: 

 

Cannot modify header information - headers already sent by (output started at /home/colly/public_html/myapp/ItemsController.php:218)

 

and here is the function inside of the itemsController that generates the error:

public function actionRedirectSomewhere($itemId) {$this->redirect(array('items/index'));}

 

It still gives me the same error if I call the function without the parameter like this: 

actionRedirectSomewhere() {$this->redirect(array('items/index'));}

 

I am not aware of any headers that I am sending.

 

How can I fix this error?

Any help would be appreciated.

 

//snapper

Share this post


Link to post
Share on other sites

What is line 218 of ItemsController.php? It's not a matter of sending headers that's causing the problem exactly, it's that the browser has already received some data, such as HTML or even a blank space, which means the redirect cannot occur. 

Share this post


Link to post
Share on other sites

Here is line 218: public function actionRedirectSomewhere($itemId) {$this->redirect(array('items/index'));}

 

It's the function call with the redirect statement. You were right. I was getting this error because I omitted the closing php tag at the end of the ItemsController. I was told I should do that  (omitting closing php tags) but did not understand when, why and where I should omit this ?> if at all.

Share this post


Link to post
Share on other sites

You should omit the PHP closing tags in scripts that are included by other scripts such as class definition files. You don't omit the closing PHP tags in view files, though.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...