Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: PHP Host

  1. #1
    New Coder
    Join Date
    Oct 2009
    Posts
    78
    Thanks
    1
    Thanked 2 Times in 2 Posts

    PHP Host

    Code:
    <?php
    /*
     * Pings all hosts and prints their status.
     * @author BinaryX
     */
    $servers = array("BinaryX@binaryx.nl@80","Server2@127.0.0.1@27015");
    $table_height = count($servers) * 10;
    ?>
    
    <table border="1" width="<?php $table_height ?>">
        <tr><td>Name</td><td>Ip</td><td>Port</td><td>Status</td></tr>
        <?php
        for ($i = 0; $i <= count($servers); $i++) {
            echo '<tr>';
            $server_info = explode("@", $servers[$i]);
            $server_name = $server_info[0];
            $server_ip = $server_info[1];
            $server_port = (int) $server_info[2];
            $fp = fsockopen(trim($server_ip), trim($server_port), $errstr, $errno, $timeout);
            $status = $fp ? "ONLINE" : "OFFLINE";
            
            echo '<td>' . $server_name . '</td><td>' . $server_ip . '</td><td>' . $server_port . '</td><td>'.$status.'</td>';
            echo '</tr>';
            $i++;
        }
        ?>
    </table>
    Displays the first row in the table just fine with the status online but it fails to parse the second one (all the variables are empty).

    Why?

    PHP you keep amazing me everytime lol.

  • #2
    New Coder
    Join Date
    Oct 2009
    Posts
    78
    Thanks
    1
    Thanked 2 Times in 2 Posts
    For the error browse to:
    Code:
    http://binaryx.nl/query/online.php

  • #3
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,032
    Thanks
    15
    Thanked 240 Times in 240 Posts
    You've got three errors in your code.
    $timeout is not defined. I just set $timeout = 30;
    You have <= in the for loop, should just be <.
    You have two $i++, one in the for loop, one at the bottom. Remove the one at the bottom.

  • #4
    New Coder
    Join Date
    Oct 2009
    Posts
    78
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Thanks worked.

  • #5
    New Coder
    Join Date
    Oct 2009
    Posts
    78
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Ok now it always returns OFFLINE but the servers that are in the array are ONLINE.
    Im trying to check if an specific Counterstrike server is online or offline.

    Why are there always problems with this?

    Code:
    $servers = array("Counterstrike Server #1@89.238.160.184@27015", "Counterstrike Server #2@89.44.246.135@27015");
    It works fine if i set binaryx.nl as address and the port as 80

    Code:
    Warning: fsockopen() [function.fsockopen]: unable to connect to 89.238.160.184:27015 (Connection timed out) in /customers/binaryx.nl/binaryx.nl/httpd.www/query/online.php on line 29
    
    Warning: fsockopen() [function.fsockopen]: unable to connect to 89.44.246.135:27015 (Connection timed out) in /customers/binaryx.nl/binaryx.nl/httpd.www/query/online.php on line 29
    Last edited by BinaryX; 10-03-2010 at 06:39 PM.

  • #6
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,032
    Thanks
    15
    Thanked 240 Times in 240 Posts
    I put that code in my page, the first server is on line, the second is not. I put the second server URL in the browser window with the port#, it also checks offline.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •