Jump to content

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?

Of course it will take longer for it to load if the server is offline.  The fsocketopen() will have to wait for the timeout to expire.

Alright, just checking to see if there was a way to make it load faster. But do you know if it will eat up alot of Bandwidth?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.