awohld has asked for the wisdom of the Perl Monks concerning the following question:

I have a script that redirects to another page when a user posts data to my script that modifies a database. How can I have my script wait 5 seconds then redirect. Here is how I'm doing some my code:
use CGI; #*****************Database code goes here, already done**** $query = new CGI; print $query->header; print "<center>Thanks for your comments!</center>"; #****Need to pause 5 seconds here before redirect print $query->redirect('http://www.yourname.com/index.html');
I know this is basic but I can't find the info on the internet.

Thanks
Adam

Replies are listed 'Best First'.
Re: Automatic redirect with a pause
by chromatic (Archbishop) on Sep 29, 2004 at 20:29 UTC

    I'm not sure that code works as you intend; on my installation, redirect() sends a HTTP Status 302 header. You've already sent a 200 OK header.

    You could use sleep, or you could send a meta refresh tag. I would think the latter would work better with your existing code.

Re: Automatic redirect with a pause
by intranetman (Acolyte) on Sep 29, 2004 at 20:22 UTC
    Instead of using  print $query->redirect('http://www.jamradar.com/speedtrap/index3.html'); You could use this
    print qq{<meta HTTP-EQUIV=REFRESH content="2; url http://www.jamrad +ar.com/speedtrap/index3.html">};
    That should do it (the number 2 is the key here). Although you could do research on the meta tag and see how they actually implement the timing. Then you could cutomize it to your liking
      Isn't the correct syntax:
      <meta http-equiv="refresh" content="5;url=http://www.jamradar.com/spee +dtrap/index3.html">
      ? You left out an = between url and site location.