我正在尝试制作一个表单,用于测试来自输入IP和端口的连接。这里的查询端口是我的代码。它没有工作dunno为什么。我从其他代码中取出了一些部件并将它们组合在一起,你可以帮助我吗?
<?php
$host = $_POST["adress"];
$port = $_POST["port"];
$query_port = $_POST["query_port"];
$timeout = 2;
$tbegin = microtime(true);
$fp = fsockopen($host, $port, $errno, $errstr, $timeout);
$responding = 1;
if (!$fp) { $responding = 0; }
$tend = microtime(true);
fclose($fp);
$mstime = ($tend - $tbegin) * 1000;
$mstime = round($mstime, 2);
?>
<div class="well">
<div class="control-group">
<label class="control-label">
<div class="row">
<div class="span4"><strong>Address <span class="text-error">*</span></strong></div>
<div class="span2"><strong>Port</strong></div>
<div class="span2"><strong>Query Port <span class="text-error">*</span></strong></div>
</div>
</label>
<div class="controls controls-row">
<div class="pull-left"><input class="span4" type="text" id="address" name="address" placeholder="Type your server address..."><input class="span2" type="text" id="port" name="port" value="7777"><input class="span2" type="text" id="port_query" name="port_query" value="27015"></div>
<div class="div-spacer pull-left"> </div>
<div id="address_notice" class="pull-left"></div>
</div>
<div class="clearfix"></div>
<span class="help-block text-info"><i class="fa fa-info-circle"></i> <small>You can leave port empty if you use the default port</small></span>
<span class="help-block text-info"><i class="fa fa-info-circle"></i>
<small>You can leave query port empty if it's the same as server port</small>
</span>
</div>
<a class="btn btn-small btn-info" method="post">Check the connection <i class="fa fa-refresh"></i></a>
<div style="height: 20px;"></div>
<div id="connection_status" class="control-group" style="display: none;">
<label class="control-label" for="connection_notice"><strong>Connection status</strong></label>
<div id="connection_notice"><?php
if($responding) {
echo "$host responded to requests on port $port in $mstime milliseconds!\n";
} else {
echo "$host is not responding to requests on port $port!";
}?>
</div>
</div>
</div>