PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
and it does not work. i read in a tutorial that header won't work if there is already text on the page. on my page there is text, and the text needs to be there. how can i make redirect work if there is text on my page?
there is also a bunch of php code before this to get postdata.
this is part of a php file that i am going to use to login and start a session then redirect users to another page.
<?php
ob_start(); //starts a info buffer...
//and optional, but better to do on last line.
ob_flush(); //empty's the buffer, but its auto done at the end of the php script. it's just cleaner. :)
?>[syntax=php]
Redirection means "no document for you here, request this one". Therefore the browser will not receive and display data after a "302 redirect" but request this new document immediately.
You might be interested in something like
<html>
<head>
<meta http-equiv="refresh" content="5; URL=http://your.serv.er/script.php" />
<title>...</title>
</head>
<body>
login successful. now redirecting...
<br />
If you're not redirected within the next 10 seconds please use this link:
<a href="http://your.serv.er/script.php">http://your.serv.er/script.php</a>
</body>
</html>
Last edited by volka on Mon Jun 11, 2007 9:59 am, edited 1 time in total.
I'm surprised no one said this, but just don't echo anything before the redirection. It's not JavaScript, so there's no timer for the redirection, thus, no reason to display "please wait."
superdezign wrote:I'm surprised no one said this, but just don't echo anything before the redirection. It's not JavaScript, so there's no timer for the redirection, thus, no reason to display "please wait."
volka wrote:therefore the browser will not receive and display data after a "302 redirect" but request this new document immediately.
superdezign wrote:I'm surprised no one said this, but just don't echo anything before the redirection. It's not JavaScript, so there's no timer for the redirection, thus, no reason to display "please wait."
volka wrote:therefore the browser will not receive and display data after a "302 redirect" but request this new document immediately.
No no volka. Of course you explained why it doesn't work. ^_^
Besides, if he was having problems with header(), I'm sure he skipped over the meta redirection code pretty quickly.
Use meta redirection like volka suggested, if you absolutely have to have content displayed before the redirect. Output buffering is not a fix in this case as it only masks what appears to be bad planning in the way the script executes (in my opinion)
Everah wrote:Use meta redirection like volka suggested, if you absolutely have to have content displayed before the redirect. Output buffering is not a fix in this case as it only masks what appears to be bad planning in the way the script executes (in my opinion)
I agree. the output buffering is the only way to keep "the text needs to be there."