I’ve got a problem with a header function using Location.
I tracked it down to, that echoing content before header doesn’t work properly.
Does the order of code causes this problem, or the order of execution?
I have seen ob_start() suggested
but I got this understanding that it is bad form.
It makes the PHP process take up extra memory as it has to put every output you generate in memory, and only then flush it when the script is done (or when you call one of the ob_end functions). Without ob_start PHP flushes only 4KB at a time, which is then the maximum amount of memory PHP will use at any given time to buffer output. With ob start the maximum is the total output of your script, which might be a lot more than 4KB.
Well, I hardly ever use it. There are some cases with functions that have no return possibility, like print_r, which you might wrap with buffering like so:
$a = array(1,2,3,4); // some test array
ob_start();
print_r($a);
$result = ob_get_clean();
$result now contains the output of the buffer, so instead of actually printing the result of print_r has been saved in the buffer and then requested using ob_get_clean().
Of course print_r is a silly example, but I couldn’t think of a better one
If it is really a hurry then you are free to use ob_start(). But because it seems that you already know that you have thrown some output before the use of header function, I would also recommend to change the coding flow in that way in which you don’t output anything before using the header() function.
You can only use the header function when no content has been sent to the browser yet. That includes an enter (or a space, or a tab) at the start of the file, before the PHP open tag!
And, just throwing ob_start() in your code would work, but it’s kind of a quick fix, not really a nice solution.
If you can’t get it to work you can your post here and take it from there.