Jump to content

[SOLVED] server status check script always saying online


Jnerocorp

Recommended Posts

Hello,

 

Im trying to make this script that checks a website server status for online or offline but it always displays offline here is the code

 

http://joeyelectric.com/demos/status/statuscheck.php

 

<?php
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Server Status Script</title>
</head>

<body>
<?php
    $online='<td style="background-color:#00FF00; padding:5px;">Online</td>';
    $offline='<td style="background-color:#FF0000; padding:5px;">Offline</td>';
    function servercheck($server,$port){
        if(empty($port)){
            $port=80;
        }
        if(empty($server)){
            $server='localhost';
        }
        $fp=@fsockopen($server, $port, $errno, $errstr, 1);
            if($fp){
                return 1;
            } else{
                return 0;
            }
        fclose($fp);
    }

$services=array(
'fewfm43f.com' => array('fewfm43f.com' => 80),
'google.com' => array('google.com' => 80)
);
?>
<table>
<?php
foreach($services as $name => $server){
?>
    <tr>
    <td><?php echo $name; ?></td>
<?php
    foreach($server as $host => $port){
        if(servercheck($host,$port)){ echo $online; }else{ echo $offline; }
    }
?>
    </tr>
<?php
}
?>
</table>
</body>
</html>

You're over complicating things and making a mistake somewhere, it would be easier to do something like this:

<?php
$list = Array(Array('fewfm43f.com', 80), Array('google.com', 80));
foreach($list as $check)
echo (@fsockopen($check[0], $check[1], $errno, $errstr, 5)) ? "{$check[0]} is Online!<br />\n" : "{$check[0]} is Offline!<br />\n" ;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.