You are here: Re: headers sent issue « PHP Programming Language « IT news, forums, messages
Re: headers sent issue

Posted by dawnerd on 08/12/06 06:41

Jerry Stuckle wrote:
> dawnerd wrote:
> > Platero wrote:
> >
> >>Hi,
> >>I've a stupid question but...
> >>
> >>The code is the following:
> >>
> >>if(($role!='tutor')&&(array_key_exists('tutor_id',$_GET)))
> >> {
> >> $possible_ids = array(2,6,7,8,9,10);
> >> $t_id = $_GET['tutor_id'];
> >>
> >> if(in_array($t_id, $possible_ids)){
> >>
> >> $query="SELECT id_class FROM class WHERE
> >>id_user='".$_GET['tutor_id']."'";
> >>
> >> $id_class=$db->get_field($query,id_class);
> >>
> >> include("print_data.php");
> >>
> >> $formButtonLabel = "Modifica";
> >>
> >> }
> >>
> >> --->else
> >>
> >> {
> >>
> >> //$my_echo = "hello";
> >> //echo $my_echo;
> >>
> >> //header('Location: http://www.google.com');
> >> //exit();
> >> }
> >>
> >> }
> >>
> >>
> >>
> >>
> >>What happens:
> >>
> >>if in the array there's what you have in $_GET, anything works.
> >>
> >>It's the else block that matters: :-)
> >>- if I ONLY print $my_echo, no problems;
> >>- if I comment $my_echo and I leave the header() uncommented, this
> >>command doesn't work (that is, the page does not redirect);
> >>
> >>What is happening?
> >>How can I solve this?
> >>
> >>I tried (in the else block) the headers_sent function too:
> >>
> >>if (headers_sent()) {
> >> $my_echo = "sent";
> >> echo $mioeco;
> >> }
> >>
> >>and it seems headers are sent, but maybe before I try to redirect.
> >>Is there a way to "clean" the headers already sent??
> >>
> >>Thanks very much,
> >>Platero
> >
> >
> > Use output buffering, should fix your problem.
> >
>
> Better to find and fix the problem than unnecessarily add overhead by
> buffering the output.
>
> Output buffering has its uses. But to use it to get around a problem in
> the code is not a good idea, IMHO.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex@attglobal.net
> ==================

I couldn't agree with you more. I find it always better to do all of
the dirty work before anything is outputted. IMO it's bad practice to
use PHP in the middle of html, unless it's used to output text.

Instead of say checking variables for errors and redirecting to a new
page in the middle of a page, do it before any html will even be
outputted, that way you are safe to set headers and the work.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация