View Single Post
Hazirak
x10 Sophmore

Hazirak's Avatar

Join Date: Dec 2007
Posts: 197
Credits: 5,961
Hazirak will become famous soon enough
Location: Georgia

Send a message via AIM to Hazirak
Quote  
01-27-2008, 04:30 AM
Re: IF/THEN statement to pick which site to navigate to?

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.
Reply With Quote
Hazirak is offlineReport Post