0

I tried sleep() function and redirecting by meta tags. I have the following code. What do i do wrong?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Please wait... Generating reports...</title>
<link rel="SHORTCUT ICON" href="images/log.png">
</head>

<body>
<center>
<div style="margin-top:200px;">
<embed src="images/loadingcircle2.swf" width="30" height="30"></embed><br />
<i style="font-family:Tahoma, Geneva, sans-serif; color:#004e49; font-size:12px;">Generating the results. Please wait...</i>
<?php
header( "refresh:5; url=results.php" ); 
?>
</div>
</center>
</body>
</html>
3
  • 2
    The header functions should be placed before sending data to the browser. Commented Apr 5, 2014 at 17:05
  • Worked :) write it as an answer so i can accept it. Commented Apr 5, 2014 at 17:08
  • Your PHP header is placed after HTML. So probably you will get error "Cannot send headers. Headers already started on..." (If your error reporting is set to ON). You must move your header to the top, that is before any HTML. Commented Apr 5, 2014 at 17:09

4 Answers 4

2

Try this -

<meta http-equiv="refresh" content="5; url=results.php" />

content is refresh time in seconds (in above example - 5 seconds)

Sign up to request clarification or add additional context in comments.

Comments

1

If you want to redirect after 5 seconds, you can do something like this:

 <div>
    Please wait... Generating reports..
 </div>

 <script type="text/javascript">
  setTimeout(function(){
      window.location.href = "result.php";
  },5000);
 </script>

Hope this helps.

Comments

0

Headers are already sent. Try to use JavaScript, or set headers at the beginning of the script.

JavaScript window.location.replace("http://stackoverflow.com");

window.location.href = "http://stackoverflow.com";

1 Comment

As per the OP's logic you must enclose this inside setTimeout() for 5 seconds.
0

Place the header function before sending data to the browser.

<?php
header( "refresh:5; url=results.php" ); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

You don't need javascript here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.