Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Load the page, send an ajax request to your page to check if it's open or not.</p> <pre><code>$.getJSON('checkstatus.php', { port: 8070 }, function (data) { if (data.status === 'on') { $('#img').attr('src', 'on.png'); } else { $('#img').attr('src', 'off.png'); } }); &lt;?php ......code..... header('content-type: application/json'); echo json_encode(array('status'=&gt;get_port_status($_GET['port']))); </code></pre> <p>edit :</p> <pre><code>//checkstatus.php &lt;?php $host = $_GET['host']; $ports = array(PORT 1, PORT 2, PORT 3, PORT 4, PORT 5, PORT 6, PORT 7, PORT 8, PORT 9); $status = array(); foreach($ports as $port) { $connection = @fsockopen($host, $port); if (is_resource($connection)) { $[$port] = 'on'; fclose($connection); } else { $[$port] = 'off'; } } header('content-type: application/json'); echo json_encode($status); ?&gt; ///status.html &lt;table id="portStatus"&gt; &lt;tbody&gt;&lt;/tbody&gt; &lt;/table&gt; &lt;script&gt; $(function () { var table = $('#portStatus tbody'); var hosts = ['host1.com', 'host2.com']; for (var i = 0; i &lt; hosts.length; ++i) { var host = hosts[i]; $.getJSON('checkstatus.php', { host: host }, function (data) { var tr = $('&lt;tr/&gt;'); tr.append($('td').html(host)); //this appends the hostname to the td; for (var port in data) { tr.append($('&lt;td&gt;&lt;img src="' + (data[port] === 'on' ? 'accept.png' : 'error.png') + '"&gt;&lt;/td&gt;'); } table.append(tr); }); } }); &lt;/script&gt; </code></pre> <p>This should give you a basic idea, try it and modify it. Note, the javascript part uses jQuery.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload