Page 1 of 1
Function header() working when it's not supposed to?!?
Posted: Tue Jun 16, 2009 3:48 pm
by Zandro237
Hey guys,
Quick breakdown of the scenario... I've got a form, and my goal in the form_submitted.php file is to process the information, output a message, and redirect to a home page about 5 seconds after outputting the message. Now I could've sworn I've always learned that nothing should to output to a page when header() is used. However, I tried it just to see what kind of error I'd get, and to my surprise, it worked perfectly. What am I missing here?
Re: Function header() working when it's not supposed to?!?
Posted: Tue Jun 16, 2009 4:01 pm
by Eric!
The rule is to always send headers first before outputing data.
Code: Select all
<html>
<?php
// This results in an error.
// The output above is before the header() call
header('Location: http://www.example.com/');
?>
Re: Function header() working when it's not supposed to?!?
Posted: Tue Jun 16, 2009 4:56 pm
by Zandro237
My bad, that's what I meant. So my point is I'm breaking that rule, but the code still works. Why?
Re: Function header() working when it's not supposed to?!?
Posted: Tue Jun 16, 2009 5:15 pm
by Eric!
Probably because you're using IE and they don't want granny's browser to say ERROR and stop working just because people don't follow good html rules.
Re: Function header() working when it's not supposed to?!?
Posted: Tue Jun 16, 2009 5:28 pm
by Zandro237
I'm testing it on both IE and Firefox. It works on both.
Re: Function header() working when it's not supposed to?!?
Posted: Tue Jun 16, 2009 5:36 pm
by Eric!
same story, they are protecting people from their own ignorance. maybe the next version won't. Do you want your browser to break every time there is a missing closing html tag? Browers trade displaying errors every time there are missing tags or general sloppy html for functionality.
Re: Function header() working when it's not supposed to?!?
Posted: Wed Jun 17, 2009 3:10 pm
by Zandro237
Great, thanks for your help.