View Single Post
Livewire
VIP User

Livewire's Avatar

Join Date: Jul 2005
Posts: 1,106
Credits: 5,900
Livewire has a spectacular aura about
Location: Ciroc

Send a message via Yahoo to Livewire
Quote  
01-25-2008, 11:23 PM
Re: IF/THEN statement to pick which site to navigate to?

Ok, keep in mind this is ABSOLUTELY POSITIVELY UNTESTED AND I DO NOT TAKE ANY RESPONSIBILITY FOR WHAT THIS CODE MAY OR MAY NOT DO PROPERLY!

Thank you.


What I would try is using something similar to this:

Code:
$site_up=fopen("www.site.com/index.php","r");
if ($site_up != false) {
fclose($site_up); //close this out so its not tying up resources.
header("Location: www.site.com");
}
else {
header("Location: www.site2.com");
}

Basically, fopen will try to open that website address. If it does open, great - the site must be up, so close the newly opened file handler and redirect the browser to that website.

If it doesn't open (fopen returns false on error), then send the browser to the other site.


It's kinda ugly though; I've never used fopen, so I've got no clue how it handles opening a page like that - in theory it should work, but I've got no testing on that, and I don't have any knowledge on how to change the headers being sent to the browser so it changes the location - I think I have it right, but I wouldn't be surprised to find it wrong >_<


In any case, the basic idea should work just fine:

1) Try to open a file on the main site.
2) If we can open it, send the user to the main site (if we can access the file, then the site must be up). If we can't, send them to the backup.


That could even be expanded so it'd go down a list of multiple backups - each time it can't open the site, have it try another one.


Hope that helps - please don't try it publically first, try it somewhere private so if it does implode, it doesn't do it to your websites >_<

Might not hurt to wait for someone else to see this and see what they say too.
__________________


Reply With Quote
Livewire is offlineReport Post