Jump to content

how to make a header location with PHP after XXX seconds?...


rootKID

Recommended Posts

Hello... the title says it all... how to make a header() location, just after some coble of seconds?...

  • Like 2
Link to comment
Share on other sites

Use the Refresh header. It starts with a timeout, and can optionally take a different URL to redirect to, e.g.

header('Refresh: 2; url=http://google.com');

will redirect to google.com after 2 seconds.

Link to comment
Share on other sites

ahh, gracias! :)...

Link to comment
Share on other sites

Guest So Called

How about an old page that has been moved to a new address? The old page says "you are being redirected to the new page, please change your bookmarks" and then 2 seconds later you're automatically on the new page.

  • Like 1
Link to comment
Share on other sites

Thanks again dsonesuk and So Called, I never thought of that that way before.

Link to comment
Share on other sites

one question getty... what does sleep?.... and sorry for late reply, have been in the schools all day... and im so tired right now :)...anyways... niche, why... simple... i suppose you have allready seemed my shop website trouble... anyways... i need this in my order_adding.php file, so that the product/order is going to be added, but in the background, while redirecting to an another location after done, and meanwhile on the page, showing the word ''Product Added''... orr somfthing like that... still working on it :)...

Link to comment
Share on other sites

one question getty... what does sleep?....
See sleep() in the PHP manual
You can do the same in PHP with:
<?phpecho "You're being redirected to... page";sleep(1000);header("Location: page.php");?>

Have you actually tried this? I'm pretty sure it isn't going to work.[[Testing...]]Yep. Doesn't work. Error 500 due to exceeded timeout. Reducing the timeout to something more reasonable, like 1 second doesn't work either. Depending on how you have your output buffering settings, one of two things happens:1. Redirect after the sleep, without the message ever being visible. This happens when output buffering is on, and since headers are sent before any content, the browser decides to ignore the content and redirect, just as it does normally with redirects.2. The message is visible, and no redirect occurs. This happens when output buffering is off, and since after the echo, the headers are already sent, there's no way for PHP to ask the browser for a redirect.
  • Like 1
Link to comment
Share on other sites

does it ''NEEDS'' to be between the 2 echoes?... the sleep?, i mean... before it will work?.

Link to comment
Share on other sites

No. The two echoes are there only for illustration purposes. How else do you distinguish a delay caused by sleep() vs. a delay caused by a slow script?

Link to comment
Share on other sites

hmm... did not think of it that way ^^'...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...