HTTP issue with redirecting

When a user enters wrong data, I want the page to show a message for 10 seconds, and then redirect to Google. When I use this code, the page redirects to Google without showing this message properly.

if($m==12 && $d==31)
    {
     echo "you entered wrong data"; 
     sleep(10) ;
     header("Location: http://google.com");
    die();
}

How can I fix it?

Related posts

1 comment

  1. You can’t respond to an HTTP request with a resource and a message that the resource that was requested can be found at a different URL.

    If you want to redirect after a time period then you need to use a document level solution (such as <meta> or JavaScript).

    For instance:

    function redirect() {
        location.replace("http://google.com");
    }
    setTimeout(redirect, 10000);
    

    That said…

    People read at different speeds and people don’t always pay continual attention to a given browser window (start something loading and then switching to another tab is not uncommon).

    I tend to work to the rule of thumb that if a message is worth displaying to the user, then it is worth displaying until they actively dismiss it.

    <p> you entered wrong data </p>
    <p> <a href="http://google.com/">continue</a> </p>
    

Comments are closed.