header problem
am 10.09.2009 08:27:29 von blueman
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 '
'.$val.'
';
}
and on admin index i get $msg and display it.
.......
//lots of stuff
$msg = $_GET['msg'];
switch($msg){
case '111' echo '
';
break;
case '421':...
}
?>
// more html and php
how can i fix this?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: header problem
am 10.09.2009 08:39:56 von George Langley
Hi Blueman. As soon as ANYTHING has been drawn to the browser, you
cannot use a header command. So you need to work through all of your
code, and ensure that all of your logic that could result in a header
call is run BEFORE you send any html code. Is going to be tricky if
mixing html and php calls.
George
On 10-Sep-09, at 12:27 AM, A.a.k wrote:
> 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 '
'.$val.'
';
> }
>
> and on admin index i get $msg and display it.
>
> ......
> //lots of stuff
>
> $msg = $_GET['msg'];
> switch($msg){
> case '111' echo '
';
> break;
> case '421':...
> }
> ?>
> // more html and php
>
> how can i fix this?
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: header problem
am 10.09.2009 08:57:55 von blueman
is there any alternative to header() for redirect users?
"George Langley" wrote in message
news:B1B897D4-7448-4B71-BFFC-3ADDC27CED32@shaw.ca...
> Hi Blueman. As soon as ANYTHING has been drawn to the browser, you cannot
> use a header command. So you need to work through all of your code, and
> ensure that all of your logic that could result in a header call is run
> BEFORE you send any html code. Is going to be tricky if mixing html and
> php calls.
>
> George
>
>
> On 10-Sep-09, at 12:27 AM, A.a.k wrote:
>
>> 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 ''.$val.'
';
>> }
>>
>> and on admin index i get $msg and display it.
>>
>> ......
>> //lots of stuff
>>
>> $msg = $_GET['msg'];
>> switch($msg){
>> case '111' echo '
';
>> break;
>> case '421':...
>> }
>> ?>
>> // more html and php
>>
>> how can i fix this?
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: header problem
am 10.09.2009 09:01:56 von gonatan
A.a.k wrote:
> is there any alternative to header() for redirect users?
As far as I know there isn't.
Is the header-error the first error on the page? If not, the other error
message itself is the reason for the header-error and will be solved if
you solve the other error.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: header problem
am 10.09.2009 09:04:22 von sandortamas
Usually, when I have to redirect the user AFTER headers has been sent (like
showing an error message), I write this:
But this will redirect the user at once. If you want the user to read the
page, you should do something in Javascript with setTimeout(func,timeout)
function.
BR,
SanTa
----- Original Message -----
From: "George Langley"
To:
Sent: Thursday, September 10, 2009 8:39 AM
Subject: Re: [PHP] header problem
> Hi Blueman. As soon as ANYTHING has been drawn to the browser, you cannot
> use a header command. So you need to work through all of your code, and
> ensure that all of your logic that could result in a header call is run
> BEFORE you send any html code. Is going to be tricky if mixing html and
> php calls.
>
> George
>
>
> On 10-Sep-09, at 12:27 AM, A.a.k wrote:
>
>> 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 ''.$val.'
';
>> }
>>
>> and on admin index i get $msg and display it.
>>
>> ......
>> //lots of stuff
>>
>> $msg = $_GET['msg'];
>> switch($msg){
>> case '111' echo '
';
>> break;
>> case '421':...
>> }
>> ?>
>> // more html and php
>>
>> how can i fix this?
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: header problem
am 10.09.2009 09:06:41 von Ashley Sheridan
On Thu, 2009-09-10 at 08:57 +0200, A.a.k wrote:
> is there any alternative to header() for redirect users?
>
> "George Langley" wrote in message
> news:B1B897D4-7448-4B71-BFFC-3ADDC27CED32@shaw.ca...
> > Hi Blueman. As soon as ANYTHING has been drawn to the browser, you cannot
> > use a header command. So you need to work through all of your code, and
> > ensure that all of your logic that could result in a header call is run
> > BEFORE you send any html code. Is going to be tricky if mixing html and
> > php calls.
> >
> > George
> >
> >
> > On 10-Sep-09, at 12:27 AM, A.a.k wrote:
> >
> >> 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 ''.$val.'
';
> >> }
> >>
> >> and on admin index i get $msg and display it.
> >>
> >> ......
> >> //lots of stuff
> >>
> >> $msg = $_GET['msg'];
> >> switch($msg){
> >> case '111' echo '
';
> >> break;
> >> case '421':...
> >> }
> >> ?>
> >> // more html and php
> >>
> >> how can i fix this?
> >>
> >> --
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >
>
>
Several:
* Javascript - not always available on your target system, or
blocked by script blocking plugins
* Meta refresh tags - should be honored by the user agent, but may
not always be.
The problem you have is not that you need to work around this 'problem'
in PHP, but you need to fix your broken code. This problem often comes
up on the list, and is usually because of extra whitespace in include
files, or errors being output to the browser which force the headers to
be sent.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: header problem
am 10.09.2009 09:16:25 von Ashley Sheridan
On Thu, 2009-09-10 at 09:04 +0200, Sándor Tamás (HostWare Kft.) w=
rote:
> Usually, when I have to redirect the user AFTER headers has been sent (li=
ke=20
> showing an error message), I write this:
>=20
>
>=20
> But this will redirect the user at once. If you want the user to read the=
=20
> page, you should do something in Javascript with setTimeout(func,timeout)=
=20
> function.
>=20
> BR,
> SanTa
>=20
> ----- Original Message -----=20
> From: "George Langley"
> To:
> Sent: Thursday, September 10, 2009 8:39 AM
> Subject: Re: [PHP] header problem
>=20
>=20
> > Hi Blueman. As soon as ANYTHING has been drawn to the browser, you can=
not=20
> > use a header command. So you need to work through all of your code, an=
d=20
> > ensure that all of your logic that could result in a header call is ru=
n=20
> > BEFORE you send any html code. Is going to be tricky if mixing html an=
d=20
> > php calls.
> >
> > George
> >
> >
> > On 10-Sep-09, at 12:27 AM, A.a.k wrote:
> >
> >> hello
> >> I recentrly uploaded my project from localhost to a hosting and found=
=20
> >> many errors and warnings which didnt have in local. one of the most=20
> >> annoying one is header('Location xxx').
> >> I have used header to redirect users from pages, and kinda used it al=
ot.=20
> >> i know about the whitespace causing warning, but most of the pages i'=
m=20
> >> sending users got html and php mixed so i'm confused about how to rem=
ove=20
> >> 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=3D'111';
> >> $user->dbupdate();
> >> header("Location: /admin/index.php?msg=3D$msg")=
;
> >>
> >> }
> >> else
> >> {
> >> foreach($errors as $val)
> >> echo ''.$val.'
';
> >> }
> >>
> >> and on admin index i get $msg and display it.
> >>
> >> ......
> >> //lots of stuff
> >>
> >> $msg =3D $_GET['msg'];
> >> switch($msg){
> >> case '111' echo '
';
> >> break;
> >> case '421':...
> >> }
> >> ?>
> >> // more html and php
> >>
> >> how can i fix this?
> >>
> >> --=20
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >
> >
> > --=20
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >=20
>=20
>=20
Don't use a timer to redirect if you want the user to read a message, as
this assumes that the visitor is a good reader. This is forgetting all
of those visitors with reading difficulties (i.e. Dyslexia), those users
who have attention problems who can't focus on text for long periods
(i.e. ADHD) and any users who rely on things such as screen readers
(which are slower than reading text yourself (if you're an average
reader!) ) or a Braille browser.
In cases such as these, it's best to let the visitor move at their own
pace and not redirect until they want to.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: header problem
am 10.09.2009 09:39:26 von Arno Kuhl
-----Original Message-----
From: A.a.k [mailto:blueman@gmail.com]
Sent: 10 September 2009 08:27 AM
To: php-general@lists.php.net
Subject: [PHP] 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 '
'.$val.'
';
}
and on admin index i get $msg and display it.
.......
//lots of stuff
$msg = $_GET['msg'];
switch($msg){
case '111' echo '
';
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