You can only use header before ANY output your script makes, output including any space or HTML before the first php tag, anything included scripts might do, and always exit or die after a redirection so you script doesn't keep churning after you've gone.
PHP Redirect
Well I guess it would be bombing because I have a header file include (but that file includes variables needed to save the data)
Is there another way to redirect the user?
It wouldn't be very HTML 4.0 compliant according to W3C, but you could print a META tag in the middle of your page, i.e.
echo '<meta http-equiv="Refresh" content="5; URL=http://www.mysite.com/path/to/file.php">';
The '5' in the content value means wait 5 seconds before redirecting. Adjust the path & delay to suit your needs.
As far as headers already sent output buffers help with that :-D
ob_start();
//content here
$content = ob_get_contents();
ob_end_clean();
echo $contents;
its almost like a function, without all the parameters/globals.
Or rearrange your code so that you generate all the headers you need to before you generate any output (and no, "including a file" is not the same thing as "generating output").
use javascript
I'd stay away from Javascript as much as possible... just for compatibilty reasons.
Javascript is a dirty little boy picking his nose, who only does things when he thinks he'll get an ice cream.
Php header redirects are like the ruby slippers of the internet and you'll find you're back in Kansas before the wicked witch can say "Terrifying monkeys".
Originally posted by murdock75
Well I guess it would be bombing because I have a header file include (but that file includes variables needed to save the data)
Is there another way to redirect the user?
Check for extra spaces following the ?> at then end of your include files. For me at least, this is the most common source of the "header already sent" message.
Yep. Remove ANY and ALL line breaks, spaces, etc. outside the <?PHP ?> tags. If you have HTML outside them, put them in an echo() somewhere so you have a chance to send out headers before that HTML is sent.
TimTimTimma's suggestion of output buffering is also ideal, too!
its usually the best way to cope with header issues I find :-P
But, like the guys said above, multiple php blocks can cause header issues, thats why I try to make all of my scripts all one php block, and output everything through echo/print