RE: header problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----Original Message-----
From: A.a.k [mailto:blueman@xxxxxxxxx] 
Sent: 10 September 2009 08:27 AM
To: php-general@xxxxxxxxxxxxx
Subject:  header problem

hello
I recentrly uploaded my project from localhost to a hosting and found many
errors and warnings which didnt have in local. one of the most annoying one
is header('Location xxx').
I have used header to redirect users from pages, and kinda used it alot. i
know about the whitespace causing warning, but most of the pages i'm sending
users got html and php mixed so i'm confused about how to remove whitespace
in a html/php file. the error is :
Warning: Cannot modify header information - headers already sent by ....
here is a simple example, user update page :
     if($valid)
                    {
                        $msg='111';
                        $user->dbupdate();
                         header("Location: /admin/index.php?msg=$msg");

                    }
                    else
                    {
                         foreach($errors as $val)
                            echo '<p id="error">'.$val.'</p>';
                    }

and on admin index i get $msg and display it.
<html>
......
//lots of stuff
   <?php
                   $msg = $_GET['msg'];
                           switch($msg){
                           case '111'       echo '<p> </p>';
                                        break;
                          case '421':...
                    }
?>
//  more html and php

how can i fix this? 
--

It's possible that on your localhost you have output_buffering set on either
in php.ini or in a .htaccess, which would avoid the displayed error about
headers. If it's switched on locally and off for your host server then
you'll get the problem you reported. Check that this is off locally (use
phpinfo) so that you can be sure your code is working properly before you
upload.

Alternatively if you want to be able to do a redirect after you've already
started your output (this is sometimes done for error handling) you could
use ob_start() to start output buffering, ob_end_clean() to clear the output
buffer and start again, and ob_flush() to send the output buffer. If you
want to continue using output buffering after an ob_end_clean() you'll have
to do an ob_start() again.

Cheers
Arno


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux