To each their own. :) It just doesn't make sense. If you're going to redirect, you don't need to show any output (server side redirect, of course).
For your case, I'd move the conditions that didn't need the header to the beginning of the select and have a case TRUE that output the header to the other cases below it... <?php include('includefile.php'); switch($_GET['page']) { case 'redirect': //redirect here break; case 'redirect2': //second redirect break; case TRUE: outputheader(); case 'page1': //output page 1 break; case 'page2': //output page 2 break; } outputfooter(); ?> ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ > -----Original Message----- > From: Leif K-Brooks [mailto:[EMAIL PROTECTED] > Sent: Friday, March 28, 2003 9:03 PM > To: [EMAIL PROTECTED] > Cc: [EMAIL PROTECTED] > Subject: Re: [PHP] Redirec.t > > Yes, I agree it's a workaround, but sometimes it's required for code > readibility (and sanity! :) For example, what if I have multiple pages > in one file, with a switch-case, and some need to redirect, but there's > a page header and footer? For example: > > <?php > include('includefile.php'); > outputheader(); > switch($_GET['page']){ > case 'foo': > //Output something here > break; > case 'bar': > //Redirect here > break > } > outputfooter(); > ?> > > The only way would be to do the footer and header on only pages that > need them, which can be lived with for a few pages, but imagine a few > hundred, or thousand! Sometimes, a quick hack is good IMO. > John W. Holmes wrote: > > >Ahhh... but the million dollar question is if you understand WHY it > >worked... > > > >Do you understand that this is a workaround and if you coded correctly > >you wouldn't need it? > > > >Output buffering to enable a header() redirect later in your code is > >almost never needed if you code correctly. Think about it: if you're > >going to redirect to a new page, why would you have output!? > > > >---John W. Holmes... > > > >PHP Architect - A monthly magazine for PHP Professionals. Get your copy > >today. http://www.phparch.com/ > > > > > > > >>-----Original Message----- > >>From: Johnny Martinez [mailto:[EMAIL PROTECTED] > >>Sent: Friday, March 28, 2003 8:37 PM > >>To: 'Leif K-Brooks'; Johnny Martinez > >>Cc: '[EMAIL PROTECTED]' > >>Subject: RE: [PHP] Redirec.t > >> > >>Thanks! That worked! > >> > >>Johnny > >> > >>-----Original Message----- > >>From: Leif K-Brooks [mailto:[EMAIL PROTECTED] > >>Sent: Friday, March 28, 2003 4:53 PM > >>To: Johnny Martinez > >>Cc: '[EMAIL PROTECTED]' > >>Subject: Re: [PHP] Redirec.t > >> > >> > >>Try putting: > >>ob_start(); > >>at the top of your file (before ANY output is done). > >> > >>Johnny Martinez wrote: > >> > >> > >>Forgive me. I'm new to php. > >> > >> > >> > >>I put the function in my function.php include file which is loaded > >> > >> > >before > > > > > >>I > >> > >>display anything. > >> > >> > >> > >>I want to redirect the browser to a new url once the php script is > >>finished. > >> > >> > >> > >>Johnny > >> > >> > >> > >>-----Original Message----- > >> > >>From: Evan Nemerson [ mailto:[EMAIL PROTECTED] > >><mailto:[EMAIL PROTECTED]> ] > >> > >>Sent: Friday, March 28, 2003 3:56 PM > >> > >>To: Johnny Martinez > >> > >>Subject: Re: [PHP] Redirec.t > >> > >> > >> > >> > >> > >>No. You have to send header information before you output anything > >> > >> > >even- > > > > > >>before the <html>. On your document, you have to put it before what is > >> > >>currently line 12. > >> > >> > >> > >> > >> > >> > >> > >>On Friday 28 March 2003 03:39 pm, you wrote: > >> > >> > >> > >>Tried that...here is the error: > >> > >> > >> > >>Warning: Cannot modify header information - headers already sent by > >> > >> > >> > >>(output > >> > >> > >> > >>started at D:\bmc\uploads\request_mdb\header.php:12) in > >> > >>D:\bmc\uploads\request_mdb\functions.php on line 16 > >> > >> > >> > >> > >> > >>Any ideas? Does this only work in the <head></head>? > >> > >> > >> > >>Johnny > >> > >> > >> > >>-----Original Message----- > >> > >>From: Evan Nemerson [ mailto:[EMAIL PROTECTED] > >><mailto:[EMAIL PROTECTED]> ] > >> > >>Sent: Friday, March 28, 2003 3:34 PM > >> > >>To: Johnny Martinez; [EMAIL PROTECTED] > >><mailto:[EMAIL PROTECTED]> > >> > >>Subject: Re: [PHP] Redirec.t > >> > >> > >> > >> > >> > >>header("Location: http://www.domain.com/admin.php > >><http://www.domain.com/admin.php> "); > >> > >> > >> > >>if you _really_ need to use your syntax, you could > >> > >> > >> > >>function redirect($uri) { header("Location: ".$uri); } > >> > >> > >> > >>On Friday 28 March 2003 03:28 pm, Johnny Martinez wrote: > >> > >> > >> > >>Hi all, > >> > >>Can someone tell me the function to redirect a browser to a specific > >> > >>page? > >> > >> > >> > >>Johnny > >> > >> > >> > >>For example: > >> > >><? > >> > >> > >> > >>code... > >> > >>code... > >> > >>code finished. > >> > >> > >> > >>redirect( "http://www.domain.com/admin.php" > >><http://www.domain.com/admin.php> ); > >> > >> > >> > >>?> > >> > >> > >> > >> > >> > >> > >> > >> > >>-- > >> > >>The above message is encrypted with double rot13 encoding. Any > >>unauthorized > >>attempt to decrypt it will be prosecuted to the full extent of the > >> > >> > >law. > > > > > > > > > > > > > > > > > > -- > The above message is encrypted with double rot13 encoding. Any > unauthorized attempt to decrypt it will be prosecuted to the full extent > of the law. > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php