Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

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.
Code:
[url=http://decisive-media.net/server.php?host=your_ip_here&port=your_port_here]http://decisive-media.net/server.php?ho ... _port_here[/url]
Which will produce the following.

IP = 209.159.212.203 : Port = 25566
server.php


Here's the PHP code.

PHP:
<div class="php" id="{CB}" style="font-family: monospace;"><ol><span style="color: #000000; font-weight: bold;"><?php

[url=http://www.php.net/header]header[/url]("Content-Type: image/png");

$im = @[url=http://www.php.net/imagecreate]imagecreate[/url](<span style="color: #cc66cc;">70, <span style="color: #cc66cc;">20) or die("Cannot Initialize new GD image stream");

$site = $_GET['host'];

$port = $_GET['port'];

 

$background_color = [url=http://www.php.net/imagecolorallocate]imagecolorallocate[/url]($im, <span style="color: #cc66cc;">0, <span style="color: #cc66cc;">0, <span style="color: #cc66cc;">0);

 

$online = [url=http://www.php.net/imagecolorallocate]imagecolorallocate[/url]($im, <span style="color: #cc66cc;">0, <span style="color: #cc66cc;">255, <span style="color: #cc66cc;">0);

$offline = [url=http://www.php.net/imagecolorallocate]imagecolorallocate[/url]($im, <span style="color: #cc66cc;">255, <span style="color: #cc66cc;">0, <span style="color: #cc66cc;">0);

 

$fp = [url=http://www.php.net/fsockopen]fsockopen[/url]($site,$port,$errno,$errstr,<span style="color: #cc66cc;">5);

[url=http://www.php.net/if]<span style="color: #b1b100;">if[/url](!$fp)

    [url=http://www.php.net/imagestring]imagestring[/url]($im, <span style="color: #cc66cc;">5, <span style="color: #cc66cc;">5, <span style="color: #cc66cc;">5,  "Offline", $offline);

[url=http://www.php.net/else]<span style="color: #b1b100;">else[/url]{

    [url=http://www.php.net/imagestring]imagestring[/url]($im, <span style="color: #cc66cc;">5, <span style="color: #cc66cc;">5, <span style="color: #cc66cc;">5,  "Online", $online);

    [url=http://www.php.net/fclose]fclose[/url]($fp);

}

[url=http://www.php.net/imagepng]imagepng[/url]($im);

[url=http://www.php.net/imagedestroy]imagedestroy[/url]($im);

<span style="color: #000000; font-weight: bold;">?>
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top