944,071 Members | Top Members by Rank

Ad:
Sep 26th, 2007
0

Php & Javascript server status detect/redirect

Expand Post »
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..

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script src="where the php script is"></script>
  2. <script>
  3. If ?server down,
  4. redirect to src="where the 'server down page' is
  5. ?
  6. </script>
  7.  



the php script

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <?php
  2. //Web Server Status v 1.4, Copyright 2002 By Ryan Schwiebert, visit http://www.schwebdesigns.com/
  3. //This script may be freely distributed providing all copyright headers are kept intact.
  4.  
  5. //Concept from:
  6. //Abax Server Status v1.04, Copyright 2002 By Nathan Dickman, visit http://www.NathanDickman.com/
  7. //Location of the live or dead server images
  8.  
  9. //Please change to your server specifications
  10. $live = "http://www.schwebhost.com/status/live.gif";
  11. $dead = "http://www.schwebhost.com/status/dead.gif";
  12.  
  13. //The status checking script
  14. //meddle at your own risk!
  15. //check for port number, default is 80
  16. $link = $_GET['link'].":";
  17. $s_link = str_replace("::", ":", $link);
  18. list($addr,$port)= explode (':',"$s_link");
  19. if (empty($port)){
  20. $port = 80;
  21. }
  22. //Test the server connection
  23. $churl = @fsockopen(server($addr), $port, $errno, $errstr, 20);
  24. if (!$churl){
  25. //echo $errstr;
  26. header("Location: $dead");
  27. }
  28. else {
  29. header("Location: $live");
  30. }
  31. function server($addr){
  32. if(strstr($addr,"/")){$addr = substr($addr, 0, strpos($addr, "/"));}
  33. return $addr;
  34. }
  35. ?>

test page (not yet on a server)

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <title>Web Server Status</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  5. </head>
  6. <body bgcolor="#FFFFFF">
  7. <table border="0" cellspacing="0" cellpadding="3">
  8.  
  9. <tr>
  10. <td width="77%"><font face="Arial, Helvetica, sans-serif" size="2">Google.com</font></td>
  11. <td width="23%"><img src="status.php?link=www.mysite.com" width="37" height="20"></td>
  12. </tr>
  13. </table>
  14. </body>
  15. </html>
Last edited by Inny; Sep 26th, 2007 at 12:14 pm.
Reputation Points: 11
Solved Threads: 6
Posting Whiz in Training
Inny is offline Offline
293 posts
since Oct 2005
Sep 29th, 2007
0

Re: Php & Javascript server status detect/redirect

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?
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Sep 29th, 2007
0

Re: Php & Javascript server status detect/redirect

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"
Reputation Points: 11
Solved Threads: 6
Posting Whiz in Training
Inny is offline Offline
293 posts
since Oct 2005
Sep 29th, 2007
0

Re: Php & Javascript server status detect/redirect

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.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Sep 29th, 2007
0

Re: Php & Javascript server status detect/redirect

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.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Sep 29th, 2007
0

Re: Php & Javascript server status detect/redirect

Ok I understand Now!

Perhaps it might be possible to simply create a
custom 404 page?
Reputation Points: 11
Solved Threads: 6
Posting Whiz in Training
Inny is offline Offline
293 posts
since Oct 2005
Sep 29th, 2007
0

Re: Php & Javascript server status detect/redirect

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.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Image Map Rollover error
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Need interactive color picker for my clients





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC