Yii Framework Forum: redirect() problems - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

redirect() problems Rate Topic: ***** 2 Votes

#1 User is offline   yii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 25-July 09

Posted 12 November 2009 - 11:10 PM

Hi,
on my testsystem is everything fine working, but on my production system, the redirect() method is nothing doing!!!!
i only get the error "Header alreday sends...."
anybody an idea?
Meine Fragen stelle ich öffentlich und baue somit eine Wissensdatenbank für andere auf!
0

#2 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 12 November 2009 - 11:18 PM

View Postyii, on 12 November 2009 - 11:10 PM, said:

i only get the error "Header alreday sends...."


This happens when output is written before the redirect. So make sure nothing is echoed etc before the redirect.
1

#3 User is offline   yii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 25-July 09

Posted 12 November 2009 - 11:24 PM

yeah i know,
but i have no echo's and no print_r before!!!

the strange thing is, that on the test-system (windows 7) everything is ok, only on the production system i have problems (debian)
Meine Fragen stelle ich öffentlich und baue somit eine Wissensdatenbank für andere auf!
0

#4 User is offline   yii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 25-July 09

Posted 12 November 2009 - 11:25 PM

2009/11/13 04:03:41 [error] [php] Cannot modify header information - headers already sent by (output started at /var/www/blog/protected/config/main.php:1) (/var/www/yii/framework/web/CHttpRequest.php:509)

Stack trace:
Meine Fragen stelle ich öffentlich und baue somit eine Wissensdatenbank für andere auf!
0

#5 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 12 November 2009 - 11:35 PM

View Postyii, on 12 November 2009 - 11:25 PM, said:

2009/11/13 04:03:41 [error] [php] Cannot modify header information - headers already sent by (output started at /var/www/blog/protected/config/main.php:1) (/var/www/yii/framework/web/CHttpRequest.php:509)

Stack trace:


I've had that before. You php files are messed up (maybe wrong charset or whatever).

Open main.php in your favorite php-editor, copy everything, paste into a new file and save. Upload and try again.

Also check transfer mode of your ftp-app. Maybe it needs a change to binary or something.

This post has been edited by qiang: 29 December 2009 - 09:52 AM

1

#6 User is offline   yii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 25-July 09

Posted 12 November 2009 - 11:42 PM

my whole workspace is in utf-8
I have load the main.php in my editor and encode it to UTF-8 and uploaded it.... nothing

my STACK TRACE

 	Cannot modify header information - headers already sent by (output started at /var/www/xyz/protected/config/main.php:1) 
	(/var/www/yii/framework/web/CHttpRequest.php:509) Stack trace: 
	#0 /var/www/blog/protected/controllers/EngineController.php(74): EngineController->redirect() 
	#1 /var/www/yii/framework/web/actions/CInlineAction.php(32): EngineController->actionSearch() 
	#2 /var/www/yii/framework/web/CController.php(300): CInlineAction->run() 
	#3 /var/www/yii/framework/web/CController.php(278): EngineController->runAction() 
	#4 /var/www/yii/framework/web/CController.php(257): EngineController->runActionWithFilters() 
	#5 /var/www/yii/framework/web/CWebApplication.php(310): EngineController->run() 
	#6 /var/www/yii/framework/web/CWebApplication.php(120): CWebApplication->runController() 
	#7 /var/www/yii/framework/base/CApplication.php(135): CWebApplication->processRequest() 
	#8 /var/www/blog/index.php(11): CWebApplication->run() REQUEST_URI=/engine/search.html?value=xyz



edit

if a call directly the URL, than is everything fine working. I have only problems with redirect()

else if ( preg_match( $pattern_alpha, $searchword ) )
{
	$this->redirect(array("engine/phrase", "value" => $searchword));
}

Meine Fragen stelle ich öffentlich und baue somit eine Wissensdatenbank für andere auf!
0

#7 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 12 November 2009 - 11:54 PM

Some binary data you can't see in a normal editor is in your main.php. Open the file in hex-editor and you will see. Either it's utf8 BOM or something else, but you need to get rid of it to get it work correctly.
0

#8 User is offline   yii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 25-July 09

Posted 13 November 2009 - 12:02 AM

i don't know where, but yes, there was an invisible character.
what editor are you using, to find so a invisible character?


edit
if i'm uploaded the file on my system, the failure is coming back!

i'm using Filezilla
Meine Fragen stelle ich öffentlich und baue somit eine Wissensdatenbank für andere auf!
0

#9 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 13 November 2009 - 12:09 AM

View Postyii, on 13 November 2009 - 12:02 AM, said:

i don't know where, but yes, there was an invisible character.
what editor are you using, to find so a invisible character?


Hex-editor? Have none installed, just remembered some month ago I had the same problem. Opened with some shareware hex-editor I found via google and fixed it.
0

#10 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 13 November 2009 - 01:57 PM

View Postyii, on 13 November 2009 - 12:02 AM, said:

edit
if i'm uploaded the file on my system, the failure is coming back!

i'm using Filezilla


I don't have FileZilla installed, but I guess you have to change the transfer mode (try binary).
0

#11 User is offline   yii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 440
  • Joined: 25-July 09

Posted 13 November 2009 - 05:36 PM

I have switch my Workspace from Windows 7 to Linux Ubuntu.
After that I have uploaded the files (under Ubuntu) with filezilla.
And everything works fine ;)


thx @ Y!!
Meine Fragen stelle ich öffentlich und baue somit eine Wissensdatenbank für andere auf!
0

#12 User is offline   killermonk 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 62
  • Joined: 27-July 09

Posted 16 November 2009 - 02:13 AM

You could also change your php.ini settings to have output buffering turned on by default. This would have solved the redirect problem.

However, because of that random character (I haven't run into it on my windows 7 stuff and I'm using utf8 and filezilla) you may have had some interesting display issues even after the output buffer configuration was changed.

In general, though, I find it a good idea to turn output buffering on by default in the php.ini file. That's just me, though.
0

#13 User is offline   Mirco 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 26-June 09

Posted 28 December 2009 - 06:16 AM

*
POPULAR

You can remove the UTF-8 BOM from the output using the ob_start function. This way you can leave the UTF-8 BOM in your source files so your editor understands it is really UTF-8.

In the /protected/config/main.php you have to add before returning the config array:
ob_start('My_OB');
function My_OB($str, $flags)
{
    //remove UTF-8 BOM
    $str = preg_replace("/\xef\xbb\xbf/","",$str);
    
    return $str;
}
return array( ... yii config array ...);


P.S. You don't have to call ob_end_flush(), php will do this automatically at the end of the script.
7

#14 User is offline   Dave 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 187
  • Joined: 09-October 08

Posted 28 December 2009 - 07:25 AM

You might have a whitespace after the closing php tag ?> in your main.php
1

#15 User is offline   Thim 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 31-December 10

Posted 31 December 2010 - 07:29 AM

View PostMirco, on 28 December 2009 - 06:16 AM, said:

You can remove the UTF-8 BOM from the output using the ob_start function. This way you can leave the UTF-8 BOM in your source files so your editor understands it is really UTF-8.

In the /protected/config/main.php you have to add before returning the config array:
ob_start('My_OB');
function My_OB($str, $flags)
{
    //remove UTF-8 BOM
    $str = preg_replace("/\xef\xbb\xbf/","",$str);
    
    return $str;
}
return array( ... yii config array ...);


P.S. You don't have to call ob_end_flush(), php will do this automatically at the end of the script.


This solution worked for me.
Is this a good solution or could this cause for problems?
Does this mean I have an UTF-8 BOM? Is there a terminal batch script to verify this? Or within the IDE (I'm using Dreamweaver CS 5 for Mac)
0

#16 User is offline   orestis 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 02-January 11

Posted 07 April 2011 - 01:22 PM

Hey

I had the same problem with you. When I started writing a new file, it's encoding was ASCII adn when I changed it to UNICODE I had this kind of problem. I am using Notepad++ and it has an option under "Encoding" which says "UTF-8 without BOM". I used to just choose encode in "UTF-8" and not UTF-8 without BOM" and that's why I had this problem. BOM adds three bytes in front of the file which are not recognized as encoding characters but as true output.

I don't know how you can change your file encoding through other editors but Notepad++ is quite helpful in that!

This is the link about BOM.
0

#17 User is offline   Haensel 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 444
  • Joined: 14-January 11
  • Location:Vienna (Austria)

Posted 15 July 2011 - 10:05 AM

Just had the same issue, but my problem were 2 whitespaces right after the php closing tag in one of my model files. So if you get this error search for anything outside your php tags
0

#18 User is offline   quantico 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 05-May 11
  • Location:Guatemala

Posted 27 October 2011 - 03:22 PM

thanks. yes is the format of the file utf8 or ansi, etc. you can not change it just in a few files. you have to be consistent. use geany in linux or notepad ++ in windows.

View PostY!!, on 12 November 2009 - 11:35 PM, said:

I've had that before. You php files are messed up (maybe wrong charset or whatever).

Open main.php in your favorite php-editor, copy everything, paste into a new file and save. Upload and try again.

Also check transfer mode of your ftp-app. Maybe it needs a change to binary or something.

0

#19 User is offline   cactork 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 22
  • Joined: 30-October 10
  • Location:Buenos Aires, Argentina.

Posted 26 November 2011 - 08:29 AM

Hi there,
I ran into the same issue but in my case everything was in UTF.
The problem was in one CController, it had two spaces into the beginning of the controller.
Attaching a shot to illustrate.

Attached File(s)


0

#20 User is offline   MichaelG 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 37
  • Joined: 19-October 10
  • Location:Roseville, CA

Posted 21 June 2012 - 11:27 PM

View PostDave, on 28 December 2009 - 07:25 AM, said:

You might have a whitespace after the closing php tag ?> in your main.php


This led to my solution.... Dave, you rock!

I enabled logging of errors and tried to reload the offending page.


protected/config/main.php
...
array('class'=>'CWebLogRoute',), // to enable debugging

This told me which file to look at...
I then opened that file, deleted lines after closing ?> tag and my problem (Captcha was failing to generate) went away!


Buys Dave virtual beer!
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users