Jump to content

Server Status Checker


Joshua F

Recommended Posts

I am trying to make a Server Status checker that uses a image to tell if it is online or not. I also am trying to make it so you can the URL as a image code(EX: Http://domain.com/statuscheck.php?ip=google.com&port=80). What I'm trying to say it, that if you do like <img src="Http://domain.com/statuscheck.php?ip=google.com&port=80"> it would go to my site, use the php script, and then have the image Online or Offline, were the <img> code was posted.

 

Here's my code Im trying to make it from.

<?php
$ip="{$_GET['ip']}";
$port="{$_GET['port']}";
if(!$sock=@fsockopen($ip,"$port", $num, $error, 5)) {
Header('Content-type: image/png');
echo"<img src='images/offline.png'>";
} else {
Header('Content-type: image/png');
echo"<img src='images/online.png'>";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/210176-server-status-checker/
Share on other sites

An HTML <img> tag is not valid image file data. You should use readfile. Like so:

 

<?php
$ip="{$_GET['ip']}";
$port="{$_GET['port']}";
header('Content-type: image/png');
if(!$sock=@fsockopen($ip,"$port", $num, $error, 5)) {
readfile('image/offline.png');
} else {
readfile('image/online.png');
}
?>

An HTML <img> tag is not valid image file data. You should use readfile. Like so:

 

<?php
$ip="{$_GET['ip']}";
$port="{$_GET['port']}";
header('Content-type: image/png');
if(!$sock=@fsockopen($ip,"$port", $num, $error, 5)) {
readfile('image/offline.png');
} else {
readfile('image/online.png');
}
?>

 

So lets say I posted a Image BBCode with this in it

[img=http://domain.com/statuscheck.php?ip=google.com&port=80]

It would put the online/offline image wherever I put that code right?

It works, but would you know how to make it so if the Server is offline, it doesn't take any longer to load. That could cause some problems if someone posted it on something.

 

Online

statuscheck.php?ip=google.com&port=80

Offline

statuscheck.php?ip=google.com&port=5555

 

Look how much longer it takes for the Offline image to load.

 

Edit: Also, if this is used a lot, would it eat up Monthly Bandwidth?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.