Simple Image Port Checker

I created this small PHP script to show online status of my various game, minecraft, etc.. servers. The PHP script is easy, the only sucky part is that there are quite a few webhosts that prevent PHP from using the port functions.

Here's the code you'd use. It has a 5 second timeout. Use the below link as a direct image.

Which will produce the following.

IP = 209.159.212.203 : Port = 25566
Image

Here's the PHP code.

  1. <?php
  2. header("Content-Type: image/png");
  3. $im = @imagecreate(70, 20) or die("Cannot Initialize new GD image stream");
  4. $site = $_GET['host'];
  5. $port = $_GET['port'];
  6.  
  7. $background_color = imagecolorallocate($im, 0, 0, 0);
  8.  
  9. $online = imagecolorallocate($im, 0, 255, 0);
  10. $offline = imagecolorallocate($im, 255, 0, 0);
  11.  
  12. $fp = fsockopen($site,$port,$errno,$errstr,5);
  13. if(!$fp)
  14.     imagestring($im, 5, 5, 5,  "Offline", $offline);
  15. else{
  16.     imagestring($im, 5, 5, 5,  "Online", $online);
  17.     fclose($fp);
  18. }
  19. imagepng($im);
  20. imagedestroy($im);
  21. ?>
Expand to see the code.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=75244