Making the page wait a few seconds then redirect

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!

Moderator: General Moderators

Post Reply
scr0p
Forum Newbie
Posts: 23
Joined: Mon May 05, 2003 6:49 pm
Location: NY

Making the page wait a few seconds then redirect

Post by scr0p »

I have a guestbook, wehn the user posts a comment, it will say "posted" then I want the page to wait 2-3 seconds and redirect back to the page showing the comments, how would I do this? I think these forums do that when I post.

ok these forums go to the 'view entry''s' page but how would I maKe it redirect automatically.
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post by llimllib »

From some website I found on google:
<META HTTP-EQUIV=Refresh CONTENT="10; URL=http://www.htmlhelp.com/">
tells the browser to load http://www.htmlhelp.com/ 10 seconds after the current document has finished loading. Not all browsers support this, so authors should provide an alternate means of moving to the new page where necessary. The Refresh header is sometimes used for "splash screens" or when a page has moved, but the technique is not very effective since users may not even be looking at the window that is to be refreshed and since it messes up the user's history on many browsers. Some search engines penalize pages that use a Refresh of a few seconds or less.
So, if you want to direct them to page x, just generate the URL dynamically.
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post by evilcoder »

use meta, or use php

Code: Select all

<?php header( "Refresh: 3; url=the url" ); ?>
Thats how i would do it.
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post by llimllib »

oh yeah, forgot about the header function...bit rusty on my php. Newbies always have trouble with it though, because they don't realize that you must send a header before *any* HTML gets sent to the client. This is becuause header($string) adds string to the HTTP response header sent by the server to the client, and most newbs don't know an HTTP header from a tomato.

That's why I prefer to tell them to dynamically generate the meta tag.
Post Reply