PHP Include Sleep on Main File
I've got an a simple include for my new project.
What happens is my included file checks a few functions and outputs the results.
If there is any kind of error I want a simple redirect to happen.
The problem I'm having is that the rest of the main file (which has the include on) keeps loading for a few seconds, before the redirect can be complete.
Is there possibly a way of sleeping the main file while the checks are made?
Thanks!
EDIT @dan:
Part of the included file:
function redirect($url) {
if(!headers_sent()) {
header('Location: '.$url);
exit;
} else {
echo '<script type="text/javascript">';
echo 'window.location.href="'.$url.'";';
echo '</script>';
echo '<noscript>';
echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
echo '</noscript>';
exit;
}
}
$url = "http://www.whatever.com/";
red开发者_Go百科irect($url);
exit;
Use die
or exit
to stop execution when you get to the point you want to redirect.
header("Location: http://www.example.com");
exit;
Are you including PHP along with HTML?
If you put all your HTML into PHP strings and don't output them until your processing is complete, that should work.
The few seconds wait you're seeing is actually the browser sending off the redirect request and waiting for a response. Unless the link between you and the client has zero latency, and your server can respond instantly, there will always be a pause for redirect.
精彩评论