x10Hosting Forums

Corporate Free Hosting for the Masses.



Register

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
x10Hosting Member

MikeHGA79's Avatar

Join Date: Dec 2007
Posts: 24
Credits: 456
MikeHGA79 is on a distinguished road
Quote  
01-25-2008, 10:03 PM
IF/THEN statement to pick which site to navigate to?

Ok...I'll do my best to explain. Essentially I have two identical websites (mirrors I guess) that are with two different hosts. Let's call them Site A & Site B. I'd like to have a 3rd site to serve as a portal. We'll call that "Portal". All users will access Portal....at that time I'd like to have some type of script that would look at Site A, if Site A is up, then proceed to Site A. If Site A is down, go to Site B. How is this possible? Currently I just have a iFrame sitting in the Portal and it's pointing to whatever site is up and/or running faster. Of course I am manually updating this throughout the week. I'm using some free website monitoring services that I thought I could use in this whole formula I'm just not sure how to implement it.

Any ideas? And oh yeah...the goal is to do all this for zero $$.

Thanks!
__________________
cPanel- MikeHGA7
Reply With Quote
MikeHGA79 is offlineReport Post
VIP User

Livewire's Avatar

Join Date: Jun 2005
Posts: 1,077
Credits: 6,195
Livewire has a spectacular aura about
Location: Ciroc

Send a message via Yahoo to Livewire
Quote  
01-25-2008, 10: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
x10 Sophmore

Hazirak's Avatar

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

Send a message via AIM to Hazirak
Quote  
01-27-2008, 03: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
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
a site without frames and a site with frame n4tec Scripts & 3rd Party Apps 18 12-31-2007 02:20 PM
Link Exchange Conor Scripts & 3rd Party Apps 117 12-09-2007 12:20 PM
My site.. Need staff... maybe... dsfreak Scripts & 3rd Party Apps 7 08-05-2005 10:07 PM
Same site, diff sections RollerC Free Hosting 2 07-28-2005 03:10 PM
New Site Design- Reward NewFuture Scripts & 3rd Party Apps 6 07-26-2005 08:28 AM


All times are GMT -5. The time now is 11:38 AM. Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0 RC7
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

Online Loans | Credit Cards | Personal Finance | Jobs for programmers | Social Networking for friends