Tested the script. It works with a few minor (and I truly mean minor) modifications.
Code:
<?php
$site_up=@fopen("http://www.site1.com/index.php","r");
if ($site_up != false) {
fclose($site_up); //close this out so its not tying up resources.
header("Location: http://www.site1.com/index.php");
}
else {
header("Location: http://www.site2.com/index.php");
}
?>
First of all, you NEED that 'http://' part infront of the URLs, otherwise it thinks you're looking for a file or directory at the current server named "www.site.com". Obviously that's not the effect we want.
Second of all, while the script works if SiteA is up, PHP will throw an error and cancel execution of the script instead of redirecting to SiteB if SiteA is not up. Thus, we need to include an @ symbol in front of the call to fopen() to suppress the warning and allow the script to continue as intended.