Reputation: 105
Hey everyone i just got my port checker to work with a dynamic image but a bad error occurs if the server is offline any help?
Here is what it says:
image too small: http://3nerds1site.com/test/finalimage.php?ip=blacknscape.no-ip.biz&port=80
this is how it should look but only works when it's online?
but anyways heres my code i do not believe its a code problem maybe my webhost which is hostgator?
<?php
$ip = $_GET["ip"];
$port = $_GET["port"];
$online = "Online";
$offline = "Offline";
$status = fsockopen($ip, $port) ? $online : $offline;
// Create a blank image and add some text
$im = imagecreatetruecolor(215, 86);
$text_color = imagecolorallocate($im, 233, 14, 91);
// sets background to Light Blue
$LightBlue = imagecolorallocate($im, 95, 172, 230);
imagefill($im, 0, 0, $LightBlue);
//Server Information
imagestring($im, 7, 5, 5, '3Nerds1Site.com', $text_color);
imagestring($im, 2, 40, 30, $ip, $text_color);
imagestring($im, 2, 40, 40, $port, $text_color);
imagestring($im, 2, 40, 70, $status, $text_color);
// Set the content type header - in this case image/jpeg
header('Content-Type: image/png');
// Output the image
imagepng($im);
// Free up memory
imagedestroy($im);
?>
Upvotes: 0
Views: 124
Reputation: 32242
Change:
$status = (fsockopen($ip, $port));
To:
$status = (@fsockopen($ip, $port));
The @
suppresses error messages when you're doing something ridiculous like this.
Alternatively, just turn off error reporting with error_reporting(0);
.
Upvotes: 1