siric Posted April 13, 2010 Share Posted April 13, 2010 Hi, I have been combing forums but cannot seem to get a answer that fits my problem. I have a link that calls another page, writes to a table and redirects back to the first page. I would like to output on the screen that the transaction has been completed, pause for a couple of seconds and then redirect to the first page. I have used sleep() but all that does is to pause the calling of the second page and then call it and redirect immediately. I have tried using flush before the sleep and before the echo but nothing works. If I use header("Refresh: 5; URL=firstpage.php"); all that does is to keep on calling the page repeatedly. Any assistance would be appreciated. Thanks Link to comment https://forums.phpfreaks.com/topic/198336-output-text-and-then-redirecting-after-a-few-seconds/ Share on other sites More sharing options...
Jax2 Posted April 13, 2010 Share Posted April 13, 2010 Just use a meta refresh ... pretty easy and works great! <meta http-equiv="refresh" content="2;url=http://YOURPAGE.php"> Ahh, and the 2, just set that to the number of seconds you want to elapse before it changes the page to the page you set with YOURPAGE.php Link to comment https://forums.phpfreaks.com/topic/198336-output-text-and-then-redirecting-after-a-few-seconds/#findComment-1040658 Share on other sites More sharing options...
teamatomic Posted April 13, 2010 Share Posted April 13, 2010 ob_start(); echo "Your Message Here"; flush(); ob_end_flush(); sleep(3); header("Location: Page.php"); exit; HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/198336-output-text-and-then-redirecting-after-a-few-seconds/#findComment-1040660 Share on other sites More sharing options...
Jax2 Posted April 13, 2010 Share Posted April 13, 2010 ob_start(); echo "Your Message Here"; flush(); ob_end_flush(); sleep(3); header("Location: Page.php"); exit; HTH Teamatomic Just out of pure curiosity, and so I know myself, is there a reason it's better to do it this way rather than a meta refresh with url redirect? Link to comment https://forums.phpfreaks.com/topic/198336-output-text-and-then-redirecting-after-a-few-seconds/#findComment-1040663 Share on other sites More sharing options...
siric Posted April 13, 2010 Author Share Posted April 13, 2010 ob_start(); echo "Your Message Here"; flush(); ob_end_flush(); sleep(3); header("Location: Page.php"); exit; HTH Teamatomic Nope that did not work. Just brought a blank screen (or stayed on the one that was there before) for 3 seconds and then went to the called (2nd) page. Link to comment https://forums.phpfreaks.com/topic/198336-output-text-and-then-redirecting-after-a-few-seconds/#findComment-1040682 Share on other sites More sharing options...
teamatomic Posted April 13, 2010 Share Posted April 13, 2010 Ya know, I think he might have to do it your way, on thinking about it even with the buffer flush a header will error. oops. HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/198336-output-text-and-then-redirecting-after-a-few-seconds/#findComment-1040683 Share on other sites More sharing options...
teamatomic Posted April 13, 2010 Share Posted April 13, 2010 Then you didnt output anything with the echo. cause I was wrong, the redirect will give an error. HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/198336-output-text-and-then-redirecting-after-a-few-seconds/#findComment-1040685 Share on other sites More sharing options...
Jax2 Posted April 13, 2010 Share Posted April 13, 2010 Just try using the meta refresh with url redirect on page2 and have it go back to page1 after so many seconds to allow them time to read the completed message? I'd be interested in knowing if it works for you ... heh Link to comment https://forums.phpfreaks.com/topic/198336-output-text-and-then-redirecting-after-a-few-seconds/#findComment-1040686 Share on other sites More sharing options...
siric Posted April 13, 2010 Author Share Posted April 13, 2010 Ok, what I did was this echo "<meta http-equiv='refresh' content='5; url=".$newpage." ' />\n"; as was suggested. Because the redirect page has parameters that change, could be newpage.php?code=1234&poll=1 or newpage.php?code=32&poll=72 etc I built the variable before the meta tags (did not know that you could do this), and it works. Thanks to all. Link to comment https://forums.phpfreaks.com/topic/198336-output-text-and-then-redirecting-after-a-few-seconds/#findComment-1040696 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.