Jump to content

Output text and then redirecting after a few seconds


siric

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.