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!
Only a select few browsers and servers support a delay in the headers. To do a countdown, you must send a page with Javascript or a refresher that updates the "clock"
You should probably use the Meta Refresh HTML tag in the HTML <head> block rather than header(). You can set it to redirect in 5 seconds AND have a countdown animation (GIF, Flash or Javascipt). With header() not output can be sent.
arborint wrote:You should probably use the Meta Refresh HTML tag in the HTML <head> block rather than header(). You can set it to redirect in 5 seconds AND have a countdown animation (GIF, Flash or Javascipt). With header() not output can be sent.
The meta refresh *does* cause problems with some proxies. (I've heard reports that it causes issues on AOL's browser as well, but I haven't ever been able to validate).
Roja wrote:The meta refresh *does* cause problems with some proxies. (I've heard reports that it causes issues on AOL's browser as well, but I haven't ever been able to validate).
Yeah, meta refresh is not as foolproof as setting headers because it is browser dependent rather than a HTTP thing. But it is pretty universally supported and will probably be fine for uses like this.
You can't do what you're wanting to do with php for a couple reasons.
1) Nothing is sent to the the client until after your script is completely finished executing. This means putting Sleep() calls in your code will only accomplish one thing: Your viewers will think your site is really slow.
2) The header() function sends a header to the client's browser. The Location header tells the browser to go to a different page. It won't display any other content you send. As soon as the client sees the Location header, its done.
You'll have to do this with either a meta tag (for a simple redirection after 5 seconds), or with Javascript if you want a nifty message. Something like this will do it: