Loading message and output_buffering

#1
[eluser]rockacola[/eluser]
Hi guys, this is a separate thread continued from http://ellislab.com/forums/viewthread/104240/.

Part of the problem I encountered with one of my project today was output_buffering.

output_buffering was set to off by default in PHP (meanwhile it is 4KB by default in PHP). With modifying php.ini out of the question.. This warning message is now all over the place
Quote:A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /usr/home/rockacol/public_html/system/application/controllers/user.php:465)

Filename: libraries/Session.php

Line Number: 662
After bit of troubleshooting and reading in thread:
http://ellislab.com/forums/viewthread/73299/
http://ellislab.com/forums/viewthread/45181/

I realised my 'Loading...' message was in the way and that's what's causing the problem.

Currently, I have implementation like this all over different controllers:
Code:
function do_something($args=array())
{
    // Credential and Authorization

    // Page Status
    echo "Updating something... please wait";
        
    // Implementations...
    
    // Redirect back to previous page
    redirect('post-action-page', 'refresh');
}

I had no problem with this in PHP, which gives me a similar effect to when you log into CI forum.
Does this mean 'echo' before redirect is not a good practise? What's a better solution to this??

#2
[eluser]Pascal Kriete[/eluser]
You cannot echo before doing a redirect, as a redirect tries to send out a header.

Instead, use a meta-refresh in the <head> of your message view:
Code:
<meta http-equiv='refresh' content='5; url=http://example.com'>

#3
[eluser]rockacola[/eluser]
I currently use a work around like this:

Code:
function do_something($args=array())
{
    // Credential and Authorization

    // Page Status
    ob_start();
    echo "Updating something... please wait";
    ob_end_flush();
    
    // Implementations...
    
    // Redirect back to previous page
    redirect('post-action-page', 'refresh');
}

But yes, in the long run, I think setup a redirect view like mentioned would be much more appropriate. Undecided


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.