How to redirect visitor to another page after certain time in PHP?

12,605

You can use sleep on the server-side then redirect to another page with header. Or you can send an HTML page with <meta> tag that specifies redirect location and delay time.

Using sleep and header

<?php
sleep(2);
header('Location: http://www.example.com/');
?>

Using <meta> tag

<meta http-equiv="refresh" content="2;url=http://www.example.com/">
Share:
12,605
spicykimchi
Author by

spicykimchi

Updated on June 04, 2022

Comments

  • spicykimchi
    spicykimchi almost 2 years

    What are some hidden tricks of PHP in putting timeout on the page and redirect it to another page?

  • FDisk
    FDisk almost 11 years
    header("refresh: 5; http://www.example.com/");