JoquiCodee
JoquiCodee

Reputation: 43

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.

Upvotes: 3

Views: 31972

Answers (3)

Phil Poore
Phil Poore

Reputation: 2256

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.

Upvotes: 4

harry
harry

Reputation: 483

// sleep php process
sleep(5);
// redirect
header("location: register.php");

Upvotes: 1

devondre
devondre

Reputation: 503

Use header Refresh. It is simple:

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

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

Upvotes: 10

Related Questions