Thread: [AJAX] Server Status Checker - Online/Offline

Results 1 to 9 of 9
  1. #1 [AJAX] Server Status Checker - Online/Offline 
    Donator [AJAX] Server Status Checker - Online/Offline Market Banned



    Join Date
    Apr 2008
    Age
    32
    Posts
    966
    Thanks given
    210
    Thanks received
    152
    Rep Power
    203
    So someone in the help section was requesting this sort of script and I remembered that I had previously built something similar a couple years back. It's probably not built the best neither have I tested it working so it will probably need a couple of edits to get working again.

    Here is what I'm releasing;





    Code:
    <?php
    if(isset($_GET['url'])) {
    	$url = $_GET['url'];
    	$port = (isset($_GET['port']) && $_GET['port'] != "") ? $_GET['port'] : 80;
    	if(!preg_match("@^https?://@",$url)) $url = "http://" . $url;
    	preg_match("@^https?://[^/]+@",$url,$parts);
    	$url = $parts[0];
    	$isup = checkit($url, $port);
    	if($isup == false) {
    		echo $isup;
    		die("<a href='$url' target='_new' rel='nofollow'>$url:$port</a> <font color='red'>is down!</font>");
    	} else
    		die("<a href='$url' target='_new' rel='nofollow'>$url:$port</a> <font color='green'>is up!</font>");
    }
    function checkit($url, $port) {
    	$url = @parse_url($url);
    	$port = intval($port);
    	if (!$url) return false;
    	$url = array_map('trim', $url);
    	$path = (isset($url['path'])) ? $url['path'] : '/';
    	$path .= (isset($url['query'])) ? "?$url[query]" : '';
    	if (isset($url['host']) && $url['host'] != gethostbyname($url['host'])) {
    		$fp = @fsockopen($url['host'], $port, $errno, $errstr, 30);
    		if (!$fp) return false;
    		fputs($fp, "HEAD $path HTTP/1.1\r\nHost: $url[host]\r\n\r\n");
    		$headers = fread($fp, 4096);
    		fclose($fp);
    		if(preg_match('#^HTTP/.*\s+[(200|301|302)]+\s#i', $headers) || ($port != 80 && $headers != "")) {
    			return true;
    		} else
    			return false;
    	}
    	else
    		return false;
    }
    ?>
    <script type="text/javascript">
    function checkServerStatus(url, port) {
    	var getURL = $('#domain').val();
    	var getPort = $('#port').val();
    	
    	$('#result').html('<font color="blue">Checking...</font>');
    	
    	$.ajax({
    		url: '/isup.php',
    		type: 'GET',
    		data: {
    			url: getURL,
    			port: getPort
    		},
    		cache: false,
    		success: function (data) {
    			console.log(data);
    			$('#result').html(data);
    		},
    		error: function () {
    			$('#result').html('<font color="red">Check failed, please try again!</font>');
    		}
    	})
    	
    	return false;
    }
    </script>
    <style type="text/css">
    #isup{text-align:center;height:120px;width:800px;}
    #isup a {font-size:20px;margin:auto;font-weight: bold;margin-top:10px;}
    #isup #result{font-size:20px;margin:auto;font-weight: bold;margin-top:10px;}
    #isup #check{vertical-align: bottom;height: 38px;}
    #isup #domain {
    	border: 1px solid rgb(148, 141, 141);
    	background: #ffc;
    	display: inline-block;
    	padding: 8px;
    	height:20px;
    	width: 200px;
    	font-size: 1.0em;
    	-moz-border-radius: 2px;
    	-webkit-border-radius: 2px;
    	border-radius: 2px;
    	-webkit-box-shadow: 5px 5px 3px rgba(0,0,0, .75);
    	-moz-box-shadow: 5px 5px 3px rgba(0,0,0, .75);
    	box-shadow: 5px 5px 3px rgba(0,0,0, .75);
    }
    #isup #port {
    	border: 1px solid rgb(148, 141, 141);
    	background: #ffc;
    	display: inline-block;
    	padding: 8px;
    	height:20px;
    	width: 50px;
    	font-size: 1.0em;
    	-moz-border-radius: 2px;
    	-webkit-border-radius: 2px;
    	border-radius: 2px;
    	-webkit-box-shadow: 5px 5px 3px rgba(0,0,0, .75);
    	-moz-box-shadow: 5px 5px 3px rgba(0,0,0, .75);
    	box-shadow: 5px 5px 3px rgba(0,0,0, .75);
    }
    #isup input[type=text]{border:2px dotted #ccc;color:#000;font-size:20px;padding:4px;width:400px;height:42px;}
    #isup input[type=text]:hover {
    	border: 1px solid rgb(148, 141, 141);;
        background: #ff6;
    }
    #isup input[type=submit]{
    	cursor: pointer;
    padding: 5px 40px;
    background: #35b128;
    border: 1px solid #33842a;
    -moz-border-radius: 2px;
    -webkit-border-radius: 2px;
    border-radius: 2px;
    -webkit-box-shadow: 5px 5px 3px rgba(0,0,0, .75);
    -moz-box-shadow: 5px 5px 3px rgba(0,0,0, .75);
    box-shadow: 5px 5px 3px rgba(0,0,0, .75);
    color: #f3f3f3;
    font-size: 1.3em;
    display: inline-block;
    }
    #isup input[type=submit]:hover{
    	background-color :#399630;
    -webkit-box-shadow: 5px 5px 3px rgba(0,0,0, .75);
    -moz-box-shadow: 5px 5px 3px rgba(0,0,0, .75);
    box-shadow: 5px 5px 3px rgba(0,0,0, .75);
    }
    </style>
    <div id="isup">
    	<form action="javascript: void(0);" onSubmit="checkServerStatus();">
    		<input type="text" size="25" id="domain" placeholder="Enter URL" />
    		<input type="text" id="port" placeholder="80" />
    		<input type="submit" id="check" value="Check" />
    	</form>
    	<div id="result"></div>
    </div>

    If you intend to use this on your website / server I would expect that you leave me the correct credits. Depending on the gratefulness of this release I may consider releasing other bits of content that I no longer use or deem useful to me any more. I haven't released this to be slated nor rated It's purely upon request so keep your comments to yourselves.
    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    Registered Member
    Anthony`'s Avatar
    Join Date
    Sep 2008
    Age
    29
    Posts
    763
    Thanks given
    75
    Thanks received
    164
    Rep Power
    204
    I think I know what thread you're talking about but he wanted it so that you don't need to click a button for it to check. Basically all you need to do is attach an event listener on the input fields and fire the AJAX request like you have already done here.
    Reply With Quote  
     

  4. Thankful users:


  5. #3  
    Registered Member
    Join Date
    Sep 2014
    Age
    26
    Posts
    97
    Thanks given
    57
    Thanks received
    11
    Rep Power
    12
    Thank you very much for this Diesel, this is what i was in need of, except click the button to check if up/down, but i changed that.
    sıhʇ dɐeɹ ot peƃauaɯ uoy snoiʇaןuʇaɹguoɔ
    Reply With Quote  
     

  6. #4  
    Donator [AJAX] Server Status Checker - Online/Offline Market Banned



    Join Date
    Apr 2008
    Age
    32
    Posts
    966
    Thanks given
    210
    Thanks received
    152
    Rep Power
    203
    Quote Originally Posted by zeptronmc View Post
    Thank you very much for this Diesel, this is what i was in need of, except click the button to check if up/down, but i changed that.
    Not a problem, I was intending to use this on my tools page for my latest community project however we thought of a completely different way to write it up.
    Reply With Quote  
     

  7. #5  
    Registered Member
    Join Date
    Sep 2014
    Age
    26
    Posts
    97
    Thanks given
    57
    Thanks received
    11
    Rep Power
    12
    Quote Originally Posted by Diesel View Post
    Not a problem, I was intending to use this on my tools page for my latest community project however we thought of a completely different way to write it up.
    This one seem to check domains only though, example: http://127.0.0.1:43594 shows down and so does http://127.0.0.1:80
    sıhʇ dɐeɹ ot peƃauaɯ uoy snoiʇaןuʇaɹguoɔ
    Reply With Quote  
     

  8. #6  
    Donator [AJAX] Server Status Checker - Online/Offline Market Banned



    Join Date
    Apr 2008
    Age
    32
    Posts
    966
    Thanks given
    210
    Thanks received
    152
    Rep Power
    203
    Quote Originally Posted by zeptronmc View Post
    This one seem to check domains only though, example: http://127.0.0.1:43594 shows down and so does http://127.0.0.1:80
    It does work for IP's also, It has been previously tested when rstoplist community existed.
    Reply With Quote  
     

  9. #7  
    Registered Member
    Join Date
    Sep 2014
    Age
    26
    Posts
    97
    Thanks given
    57
    Thanks received
    11
    Rep Power
    12
    Quote Originally Posted by Diesel View Post
    It does work for IP's also, It has been previously tested when rstoplist community existed.
    Hmm, aight i will just look more at it, currently it shows online if domain port 8090, but down if ipadress port 8090
    sıhʇ dɐeɹ ot peƃauaɯ uoy snoiʇaןuʇaɹguoɔ
    Reply With Quote  
     

  10. #8  
    KNOWLEDGE IS POWER

    OG KingFox's Avatar
    Join Date
    Dec 2006
    Age
    33
    Posts
    1,683
    Thanks given
    628
    Thanks received
    1,062
    Rep Power
    750
    this is WAY too complex for just a server status checker.

    Attached image
    Reply With Quote  
     

  11. Thankful user:


  12. #9  
    Donator [AJAX] Server Status Checker - Online/Offline Market Banned



    Join Date
    Apr 2008
    Age
    32
    Posts
    966
    Thanks given
    210
    Thanks received
    152
    Rep Power
    203
    Quote Originally Posted by King Fox View Post
    this is WAY too complex for just a server status checker.
    Someone requested it and it's something I no longer use as we've re-written this already.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Server status Checker
    By Nathan R in forum Tools
    Replies: 12
    Last Post: 12-09-2010, 01:42 AM
  2. Server status - players online.
    By jameskmonger in forum Application Development
    Replies: 9
    Last Post: 05-18-2009, 08:29 PM
  3. Replies: 28
    Last Post: 05-04-2008, 07:38 PM
  4. Server Status Checker
    By Chimeric in forum Tools
    Replies: 25
    Last Post: 02-07-2008, 01:30 AM
  5. Server Status checker.
    By Stumikaz in forum RS2 Server
    Replies: 5
    Last Post: 11-11-2007, 08:05 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •