我有一个非常简单的端口检查,我希望张贴在线/离线状态的情况下,我相信是一个动态的图像。如果它是在线的,它不会给我和错误,也不会给我任何东西,但是它不会离线或离线地发布资源id #1,这是我的代码:
<?php
$ip = $_GET["ip"];
$port = $_GET["port"];
$online = "Online";
$offline = "Offline";
$status = (fsockopen($ip, $port));
if ($status) {
$online;
} else {
$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);
?>有人能给我一些有用的信息吗?
这也是我的输出:

发布于 2013-08-12 21:59:06
这是毫无意义的:
$status = (fsockopen($ip, $port));
if ($status) {
$online;
} else {
$offline;
}这也是问题的原因,因为$status永远不会是可打印的东西(条件线中的行根本不改变它的值)。它要么是false (在这种情况下,您将看不到任何期望“脱机”的地方),要么是一个资源(在这种情况下,您将看到类似于"Resource #1“的内容)。
将上述所有代码替换为
$status = fsockopen($ip, $port) ? $online : $offline;发布于 2013-08-12 21:59:10
变化
if ($status) {
$online;
} else {
$offline;
}至
if ($status) {
$status = $online;
} else {
$status = $offline;
}在一个if块中只使用$online本身并不能做任何事情。您必须对它做一些事情;也就是说,将它赋值给一个变量以便稍后输出。
发布于 2013-08-12 21:59:53
您正在将$status打印到图像中,这是fsockopen()调用的结果,而不是您在顶部指定的字符串。试试这个:
$status = (fsockopen($ip, $port));
if ($status) {
$status = $online;
} else {
$status = $offline;
}https://stackoverflow.com/questions/18197317
复制相似问题