[FX.php List] PHP question...
Leo R. Lundgren
leo at finalresort.org
Wed Apr 29 09:00:15 MDT 2009
29 apr 2009 kl. 16.47 skrev Bob Patin:
> but for some reason, it doesn't actually send the user to the next
> page. I can test and confirm that the IF statement does validate and
> the code within IS run, but why doesn't it send the user to the next
> page? Is it because a lot of the HTML has already loaded?
True. header() tries to send an HTTP header, and these come before the
content. You're just too late :P
> Is there another way to redirect after the BODY of a page has
> already started loading?
If you really cannot do the processing and logic you require at the
top of the page, I can think of these ways to solve your problem
(there might be other ways, just thinking about it quickly):
- Instead of a HTTP header to redirect the user, use a <script> in
the page/out, that will trigger a redirect. Not a very nice solution
though.
- Use output buffering. See http://se.php.net/manual/en/book.outcontrol.php
. What you would do is:
- Put ob_start() at the start of your PHP file, to make all output
(except headers) stay in a buffer until you tell it otherwise.
- Then you carry on as normal, outputting that main part of your page.
- Then in your "logic point", if you need to redirect the user you
just do the header() call you already have. As the output is buffered,
no output has been sent, and the header is fine.
- If you don't need to redirect, just continue with your page, and ..
- .. at the end you put a call to ob_end_flush() to make PHP output
everything in the buffer to the browser.
-|
More information about the FX.php_List
mailing list