Jump to content
rootKID

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

Recommended Posts

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

  • Like 2

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

ahh, gracias! :)...

Share this post


Link to post
Share on other sites

I'm interested in why you want to do this?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Guest So Called

Well, yeah, but the OP didn't provide sufficient information to determine that.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

You can do the same in PHP with:

<?phpecho "You're being redirected to... page";sleep(1000);header("Location: page.php");?>

Edited by getty

Share this post


Link to post
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 :)...

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...