form submission error

I have a registration form which works fine on localhost , but on the online server I get this error message when submitting the form(and even when the form data is getting saved in the database):

PHP Error

Cannot modify header information - headers already sent by (output started at /home/user/public_html/yiitest/protected/models/User.php:1)


public function redirect($url,$terminate=true,$statusCode=302)

654 {

655 if(strpos($url,’/’)===0)

656 $url=$this->getHostInfo().$url;

657 header('Location: '.$url, true, $statusCode);

658 if($terminate)

659 Yii::app()->end();

660 }

here is the code for the relevant action:

public function actionRegister()


          $model=new User('register');

         // uncomment the following code to enable ajax-based validation


         if(isset($_POST['ajax']) && $_POST['ajax']==='user-register-form')


             echo CActiveForm::validate($model);









                  // form inputs are valid, do something here









looks like the error comes from the line: $this->redirect(array(‘site/login’));

Hi, it’s most likely a difference in the PHP configuration options, I’m taking a wild stab here but if your not getting that error on your dev server then maybe it’s an output buffering setting.

The thing is that your code is probably not right because in a framework like Yii, ideally the code would execute the same way in both environments.

So what I think is going on:

  • On dev ob_start is turned on by default somewhere. It’s not turned enabled on your production server.

EDIT: It looks like /home/user/public_html/yiitest/protected/models/User.php:1 is somehow sending output, make sure you don’t have any whitespace outside your <?php ?> tags in your User.php model. Also make sure you aren’t echo’ing or print’ing anything in this file.