Test connection ip/port from input form
<p>I'm trying to make a form that test connection from the input IP and port &amp; query port here is my code. It's not working dunno why. I took some parts from other codes and put them together, can you please help me with that?</p>

<pre><code>&lt;?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);
?&gt;

&lt;div class="well"&gt;
    &lt;div class="control-group"&gt;
        &lt;label class="control-label"&gt;
            &lt;div class="row"&gt;
                &lt;div class="span4"&gt;&lt;strong&gt;Address &lt;span class="text-error"&gt;*&lt;/span&gt;&lt;/strong&gt;&lt;/div&gt;
                &lt;div class="span2"&gt;&lt;strong&gt;Port&lt;/strong&gt;&lt;/div&gt;
                &lt;div class="span2"&gt;&lt;strong&gt;Query Port &lt;span class="text-error"&gt;*&lt;/span&gt;&lt;/strong&gt;&lt;/div&gt;              
            &lt;/div&gt;
        &lt;/label&gt;
        &lt;div class="controls controls-row"&gt;
            &lt;div class="pull-left"&gt;&lt;input class="span4" type="text" id="address" name="address" placeholder="Type your server address..."&gt;&lt;input class="span2" type="text" id="port" name="port" value="7777"&gt;&lt;input class="span2" type="text" id="port_query" name="port_query" value="27015"&gt;&lt;/div&gt;
            &lt;div class="div-spacer pull-left"&gt;&amp;nbsp;&lt;/div&gt;
            &lt;div id="address_notice" class="pull-left"&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="clearfix"&gt;&lt;/div&gt;
        &lt;span class="help-block text-info"&gt;&lt;i class="fa fa-info-circle"&gt;&lt;/i&gt; &lt;small&gt;You can leave port empty if you use the default port&lt;/small&gt;&lt;/span&gt;
        &lt;span class="help-block text-info"&gt;&lt;i class="fa fa-info-circle"&gt;&lt;/i&gt; 
           &lt;small&gt;You can leave query port empty if it's the same as server port&lt;/small&gt;
        &lt;/span&gt;   
    &lt;/div&gt;

    &lt;a class="btn btn-small btn-info"  method="post"&gt;Check the connection &lt;i class="fa fa-refresh"&gt;&lt;/i&gt;&lt;/a&gt;

    &lt;div style="height: 20px;"&gt;&lt;/div&gt;
    &lt;div id="connection_status" class="control-group" style="display: none;"&gt;
        &lt;label class="control-label" for="connection_notice"&gt;&lt;strong&gt;Connection status&lt;/strong&gt;&lt;/label&gt;
        &lt;div id="connection_notice"&gt;&lt;?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!";
            }?&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
</code></pre>