Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP redirect after 5 seconds

How do I redirect page with PHP after 5 seconds to file register.php? No Javascript or other code, just plain PHP.

Is it possible? How do I do it? I've seen Location: header.

like image 312
JoquiCodee Avatar asked Apr 27 '26 12:04

JoquiCodee


2 Answers

Use header Refresh. It is simple:

header("Refresh:5; url=register.php");

It should work, make sure no output is before this header.

like image 66
devondre Avatar answered Apr 30 '26 04:04

devondre


You have a few options:

  1. Refresh Header

    header("Refresh:5; url=register.php");
    
  2. Sleep then Location Header

    sleep(5);
    header("Location: register.php");
    

The first option is best, the sleep in the 2nd is blocking and could be used to DDos your service.

like image 21
Phil Poore Avatar answered Apr 30 '26 05:04

Phil Poore



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!