A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearPHP Redirect Pause - page 1
User InfoPosts
PHP Redirect Pause#1
How do I pause a page for a certain amount of seconds before redirecting the user to another HTML/PHP page using PHP?

posted date: 2009-04-09 23:45:00


Re: PHP Redirect Pause#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-09 23:45:01


Re: PHP Redirect Pause#3
Update: this works, but may not be the most appropriate solution for this situation. See comments.Might this be what you are looking for?<?phpsleep(5);header("Location: http://www.example.com/");exit();?>

posted date: 2009-04-09 23:47:00


Re: PHP Redirect Pause#4
The other 2 options are a Javascript redirect using setTimeout() or a meta refresh tag with a timeout.

posted date: 2009-04-09 23:48:00


Re: PHP Redirect Pause#5
Low-tech solution requiring no Javascript or even PHP:<html><head> <title>Redirecting...</title> <meta http-equiv="refresh" content="10;URL=http://www.newsite.com"></head><body> You are being automatically redirected to a new location.<br /> If your browser does not redirect you in 10 seconds, or you do not wish to wait, <a href="http://www.newsite.com">click here</a>. </body></html>The advantage of this solution over using the "Location:" header is that you don(t need to pause the script execution, which will appear to the user as if the server is busy or their connection has hung.This solution also gives the user the option of proceeding to the new page immediately rather than having to wait x number of seconds while their browser displays no information.Edit: I think it(s also worth noting that if you do decide to use the the header() method, you need to make sure your sleep() duration isn(t too long. I think most browsers generate a connection timed out after not receiving any data from the server for 1 minute.

posted date: 2009-04-09 23:56:00


Re: PHP Redirect Pause#6
Be carefully - some browser (like chrome and opera) won't take this way correctly

posted date: 2009-04-10 00:31:00


Re: PHP Redirect Pause#7
Does this really work? I thought that with the sleep function the browser just keep'n'load the page for (in your example) 5 seconds.. but without throw out the output

posted date: 2009-04-10 00:34:00


Re: PHP Redirect Pause#8
Really? I did not know that. Well, at least they have the link to click on then.

posted date: 2009-04-10 00:42:00


Re: PHP Redirect Pause#9
This one should works:<?phpheader((Refresh: 5; URL=http://yoursite.com/page.php();//other code?>and will allow your user to see whatever kind of output you want (You(ll be redirected in X Seconds, click yere if dont, etc..)

posted date: 2009-04-10 00:44:00


Re: PHP Redirect Pause#10
@DaNieL I haven't tested this, so you may be correct that it does or does not work depending on server settings or the time / place that you call this code.

posted date: 2009-04-10 00:53:00


Re: PHP Redirect Pause#11
I've just tested, it works, but prevent all the others output too.. afaik the sleep sleep() funcion keep in pause the entire php render, so imho shouldn't be used for this kind of issues

posted date: 2009-04-10 00:57:00


Re: PHP Redirect Pause#12
Yes, i dont remember exacly if the browser who didnt handle it properly are safari, opera or chrome.. i remember that as 2 of them.... but maybe they fixed this issue in the time

posted date: 2009-04-10 00:59:00


select page: « 1 2...»
Copyright ©2008-2017 www.momige.com, all rights reserved.