timed redirect to another URL

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
Fari
Forum Commoner
Posts: 42
Joined: Thu Sep 19, 2002 8:41 pm
Location: Timmins - Ontario

timed redirect to another URL

Post by Fari »

..hi guys .. how can I combine 'header' with a timer to redirect a page after a set time expires? has anyone done anything like this?

ta - Fari
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

do you want to redirect the page after the page has fully loaded? if so, you can't. the php script as finished executing by that time and therefore has no control over the current function of the page (ie. refreshing). you can use the the meta tag to achive this kinda thing.

<meta http-equiv="refresh" content="value [; URL]" />
where value is the number of seconds to wait before refresh and URL, if specified, is the page to refresh to and if not specified, refreshes the current page.
User avatar
BigE
Site Admin
Posts: 139
Joined: Fri Apr 19, 2002 9:49 am
Location: Missouri, USA
Contact:

Post by BigE »

Yes, you should most likely use the <meta> redirect to do this. However, if your set on using PHP to do this, you can check out sleep() php.net/sleep and header() php.net/header which will accomplish the same thing.
User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Post by Kriek »

header() refresh/redirect with delay.

Code: Select all

<?php header("refresh: 5; url=http://$SERVER_NAME/page.php"); ?>
header() refresh/re-direct without delay

Code: Select all

<?php header("Location: http://$SERVER_NAME/page.php"); ?>
Post Reply