Hey i need help with this server status script. What is happening is when I use this script It doens’t display anything at all.. This is ym current code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');
$ip = $_GET['ip'];
$port = $_GET['port'];
/* Attempt to open */
$im = @imagecreatefrompng('status.png');
// Set the content-type
header('Content-type: image/png');
//check to see if server is online or offline
$socket = fsockopen($ip, $port, $errno, $errstr, 1);
if($socket) {
$text = 'Online';
$color = imagecolorallocate($im, 0,255,0);
} else {
$text = 'Offline';
$color = imagecolorallocate($im, 255,0,0);
}
/* See if it failed */
if($im)
{
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// Replace path by your own font path
$font = 'Arial Bold.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $color, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $color, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
} else {
print("Error finding image $image</br>");
}
?>
What I want it do to is check if a server is online, and if it is then display Online on the background image status.png but when I use the following url format: Myurl/getStatusImage.php?ip=94.249.187.82&port=25565 It displays a blank page.
Thanks for any help.
Congrats fella, it’s time to get acquainted with programming.
And learn some debugging techniques.
In fact, not a soul in the world can tell you what’s wrong with your code, on your server in your environment. But only your own code you can ask for it.
First of all, comment out
headerline and see what it says.and – oh – remove all the boody @’s from the code!
so you’ll be able to see if any error occurred.
Then divide your code into 2 chunks – getting info part and creating an image part. Run both separately until each works perfect. And only then combine them up.