简体   繁体   中英

How can I refresh a page/frame when a server not found error page is displayed?

I've searched but haven't been able to find any discussion on this topic:

I have a private webpage (implemented in php) that scrolls through a few different php pages displaying info then refreshing to the next one every minute for use in a fire station displaying latest jobs, weather etc. I currently use header( 'refresh: 60; url=screen2.php' ); in each php file simply pointing to the next file..

The problem is that every once in a while the page fails to load for one reason or another, at which point the "Server not found" page is displayed. When that happens of course the refresh instruction is lost and error page stays there until someone notices the problem and manually refreshes the page. Not ideal..

I should mention the page is displayed on multiple monitors around the fire station and the pc running it is locked away. Hence the hassle of manually refreshing it every so often!

It's important if possible to automatically recover from this situation without human intervention. Is there any way, using frames, php, javascript or otherwise, to refresh again if the error page is shown?

Any ideas would be greatly appreciated.

Thanks! Adam

You could just use javascript window.location inside a setTimeout function or a meta refresh tag.

There's no reason to need to do it on the PHP side unless you care whether the user can change the refresh information.

You say it "fails to load for one reason or another" - do you know why this is? If the problem is at your server end, then you could set up your server so that its 404 response (or 500 internal server error response, or whatever error it is) contains the header to redirect to the start PHP page.

If the issue is DNS or connection related - ie. the server isn't even contacted and so the "not found" error page is being displayed by the browser, then what you could do is alter this page. This is not easy to do, but in Firefox you can eg follow the instructions on http://forums.mozillazine.org/viewtopic.php?f=7&t=492177&start=0 in order to customise the error page shown.

Other than that, it might be better to fix the problem with the page failing to load, that might be simpler :)

You could also save the information in a session. http://php.net/manual/en/features.sessions.php

Another way that is server-independent is the Web Storage API of javascript. Most modern browsers already support it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM