Log in

View Full Version : I need to redirect to a page if another page is not found



ted
04-14-2008, 08:43 PM
Hello,

I have a HTML page, which is hosted on the net
and inside the html page there is an iframe which is hosted in my computer

If someone tried to see this page while my computer is closed, a big white box that says "connection timed out" will appear (on firefox) and "Internet Explorer cannot display the webpage" (on IE) and so on... you know it better

And the question is:
Is there any way to use some kind of script so as to redirect that iframe to use another static page when the page on my computer is not available ?

Thank you all in advance,
Ted

thetestingsite
04-15-2008, 03:35 AM
Can you use php or any other server side script on your server (the one on the net)? If so, you could use something like the following:



<?php
error_reporting(0);

if (fsockopen("www.yoursite.com", 80, $errno, $errstr, 30)) {
header('Location: http://www.yoursite.com/computer.html');
}
else {
header('Location: http://www.other-site.com/page.html');
}
?>


Then, just have you iframe point to that php page. If you have any questions on the above code, just let me know.

Hope this helps.

ted
04-15-2008, 08:08 PM
MANY THANKS !

I encountered some problems at first, but when I moved my page to another server with a bit better php support, your script worked like charm!

THANKS AGAIN !