Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Redirect Pause

Tags:

redirect

php

How do I pause a page for a certain amount of seconds before redirecting the user to another HTML/PHP page using PHP?

like image 446
Paradius Avatar asked Apr 10 '09 07:04

Paradius


People also ask

How to delay a redirect in PHP?

We can use the sleep() method of PHP along with the above method to delay redirect for a few seconds. If we need to wait, users for 5 or 10 seconds we just need to use sleep(5) or sleep(10) before the header method.

How to redirect in PHP after 5 seconds?

You can try this: header('Refresh: 10; URL=http://yoursite.com/page.php'); Where 10 is in seconds.

How to pause in PHP?

If you need to pause the execution of your PHP script for times shorter than a second, you will need to use the usleep() function. With this function, you can specify the number of microseconds you want the script to sleep. A microsecond is one-millionth of a second.

What is the use of sleep in PHP?

The sleep() function delays execution of the current script for a specified number of seconds. Note: This function throws an error if the specified number of seconds is negative.


1 Answers

This one should works:

<?php
header('Refresh: 5; URL=http://yoursite.com/page.php');
//other code
?>

and will allow your user to see whatever kind of output you want (You'll be redirected in X Seconds, click yere if dont, etc..)

like image 178
Strae Avatar answered Sep 28 '22 02:09

Strae