User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 456,509 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,657 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 4572 | Replies: 6
Reply
Join Date: Oct 2005
Posts: 236
Reputation: Inny is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 6
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Php & Javascript server status detect/redirect

  #1  
Sep 26th, 2007
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>
Last edited by Inny : Sep 26th, 2007 at 12:14 pm.
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 72
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Practically a Master Poster

Re: Php & Javascript server status detect/redirect

  #2  
Sep 29th, 2007
i am trying to understand exactly what you are trying to do. are you checking the status of other peoples servers for them and redirect to a page to show if their server is down?
Reply With Quote  
Join Date: Oct 2005
Posts: 236
Reputation: Inny is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 6
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Php & Javascript server status detect/redirect

  #3  
Sep 29th, 2007
I want to detect when the server of my page goes down and have it redirect to a server status page page which i will create and host elswhere. this will have a message ..."sorry our server is temporarily down for repairs/upgrade bla bla, try again later"
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
Reply With Quote  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 72
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Practically a Master Poster

Re: Php & Javascript server status detect/redirect

  #4  
Sep 29th, 2007
if your server is down you can't run any scripts to detect it or redirect. no matter what you will get a 404 error. i can't think of anyway to do this. i will think about it some more and get back with you.
Reply With Quote  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 72
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Practically a Master Poster

Re: Php & Javascript server status detect/redirect

  #5  
Sep 29th, 2007
pretty much the only way i can think of is to have your site directed to a different server other than the one that holds your files. on the that server is a php page to detect the status of your server. if its running, the code with direct to that server. otherwise it will display that message you want. to me this seems pretty pointless. if your site is down, its down. the people that are trying to view your website will get over it.
Reply With Quote  
Join Date: Oct 2005
Posts: 236
Reputation: Inny is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 6
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Php & Javascript server status detect/redirect

  #6  
Sep 29th, 2007
Ok I understand Now!

Perhaps it might be possible to simply create a
custom 404 page?
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
Reply With Quote  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 72
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Practically a Master Poster

Re: Php & Javascript server status detect/redirect

  #7  
Sep 29th, 2007
i was going to say that next, but you already figured it out. good for you. its really easy to do this but your hosting company might have specific rules for creating custom 404 pages. my godaddy server has a special program for creating these type of pages. you will have to check with your hosting to see if you can do this. if not you can use a .htaccess file.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 3:47 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC