Header placement delay

I have the following php code that I want to add a delay too:

<?php
    echo "Message has been sent.";
    header("Location: page2.php", true, 303);
    exit;
?>

The above code is too fast, so I do not see the message:

I tried:

<?php
    sleep(5);
    echo "Message has been sent.";
    header("Location: page2.php", true, 303);
    exit;
?>

This also does not display the message, but it is sleeping for 5 seconds, which is a waste of time.

How do I get it to display a message 5 seconds before redirecting?

+5
source share
6 answers

You cannot do this with an HTTP redirect, as this redirect will happen as soon as the browser receives the header. Instead, use the update redirection in the header:

header( "Refresh:5; url=http://www.example.com/page2.php", true, 303);

, , ( , HTML- ):

<meta http-equiv="refresh" content="5;url=http://www.example.com/page2.php"> 

:

. X . , , Netscape - .

+24

:

<script>
window.setTimeout(function() {
    window.location = 'page2.php';
  }, 5000);
</script>
<p>Message has been sent.</p>
+3

:

<?php

    echo "Message has been sent.";
    sleep(5);
    header("Location: page2.php", true, 303);
    exit;
?>
+3

, (Location). , , . , echo '<meta http-equiv="refresh" content="5;URL=\'http://example.com/\'">';

. ( ) JS, .

+2

, , , , , , .

: reset ?

and this is how I fix my problem using my .form-control class

$(document).ready(function() {
   $(".form-control").val('');
});
0
source
header( "Refresh:time; url='filelocation'");
0
source

All Articles