Need help to set up a few files. I want to use a php script to detect server status, and javascript to automatically redirect to a server status page [on another server obviously] (only if the server is down)
immediately rather than get a 404 error.
I have a php script to detect server status and I can build a 'server down page' to redirect to, but im lost on the javascript! please help?
I image something like..
<script src="where the php script is"></script>
<script>
If ?server down,
redirect to src="where the 'server down page' is
?
</script>
the php script
<?php
//Web Server Status v 1.4, Copyright 2002 By Ryan Schwiebert, visit http://www.schwebdesigns.com/
//This script may be freely distributed providing all copyright headers are kept intact.
//Concept from:
//Abax Server Status v1.04, Copyright 2002 By Nathan Dickman, visit http://www.NathanDickman.com/
//Location of the live or dead server images
//Please change to your server specifications
$live = "http://www.schwebhost.com/status/live.gif";
$dead = "http://www.schwebhost.com/status/dead.gif";
//The status checking script
//meddle at your own risk!
//check for port number, default is 80
$link = $_GET['link'].":";
$s_link = str_replace("::", ":", $link);
list($addr,$port)= explode (':',"$s_link");
if (empty($port)){
$port = 80;
}
//Test the server connection
$churl = @fsockopen(server($addr), $port, $errno, $errstr, 20);
if (!$churl){
//echo $errstr;
header("Location: $dead");
}
else {
header("Location: $live");
}
function server($addr){
if(strstr($addr,"/")){$addr = substr($addr, 0, strpos($addr, "/"));}
return $addr;
}
?>
test page (not yet on a server)
<html>
<head>
<title>Web Server Status</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<table border="0" cellspacing="0" cellpadding="3">
<tr>
<td width="77%"><font face="Arial, Helvetica, sans-serif" size="2">Google.com</font></td>
<td width="23%"><img src="status.php?link=www.mysite.com" width="37" height="20"></td>
</tr>
</table>
</body>
</html>