You need to rewrite the code so that header() will be the first thing the file outputs.
Mixing HTML code with PHP code can get real messy and is best avoided if possible. That said, you could probably get away with putting all the mark-up into $variables and echo them later if they still need to be output after the header conditional blocks.
nobody has led me to believe they are the same language… I have been converting an entire website… of course I know they’re different…
it seems this redirect problem is more than a simple “language” problem though…
why on earth can you not redirect to another page after any output is sent… this is a “language” issue? well, I don’t know what to say, I don’t get this…
Sending output – that is, an HTTP response body – implicitly means sending HTTP response headers, because in an HTTP message, the headers always come before any body content. Therefore, if you try to add or change headers after the headers have already been sent, then it’s too late.
The Java code you posted gets away with this because it isn’t actually sending any output yet. Instead, it’s collecting headers and content in a response object.
I’m not a 100% certain, but are not JSP files compiled?
PHP files are not compiled.
Your misunderstanding about how the PHP header function works is not a problem with PHP, but stems from your lack of understanding how HTTP works.
Don’t feel bad about it, covering HTTP could fill a book on its own. And it’s not really something most PHP programmers get into very deeply.
Just accept that if you are working with the PHP header function it must be the first thing the file sends as output
I have seen hackish code using output buffer functions to get around this requirement, and I guess in some cases it might actually be absolutely neccessary. But IMHO from where I’ve seen it used it’s been used more as a way to avoid rewriting the code in a better way.
If you haven’t seen the “headers already sent” error message, you must have error reporting and display turned off. I strongly suggest you turn them on while you’re converting the JSP to PHP. Doing so will save you a lot of bewilderment.
oh brother… yes JSP’s are actually compiled… (was wondering if that’s the case with PHP…
what I’m trying to do with PHP is exactly the same thing I’m doing with the Java/JSP code I posted (which is in a scriptlet, i.e., wrapped in <%…%> tags)
actually in JSP (and will be the same in PHP) this redirect stmt is in a file that has no HTML output… it’s in an include (i.e, included) file…
I don’t see “headers already sent” messages, what I get is stuff like "the page isn’t redirecting properly (FF), or “This webpage has a redirect loop” (Chrome)