• Log in or sign up for an account here: https://www.sythe.org/login

[PHP] Server Status

syth4

Active Member
Joined
Jan 28, 2007
Sythe Gold
1
Messages
173
Discord Verified
How do I make a server status page like Mopar does?
Thanks :)
 
Code:
<?php
phpinfo();
?>

If you mean like, IP address, file space, etc all in an image or something, you'll have to learn the image library that comes with php.
 
Discord Verified
I mean just basic like this

World 1 Online GoldScape.servegame.com
 
Two Factor Authentication User
PHP:
<?php 
/* ################################## 
* This function will check for all ports and send an email if one is down. 
* This will also use the Name of the Server for easy identification. 
* 
* This script may NOT be distributed without express written 
* permission from Jaguar Technologies, LLC . 
* -- www.jaguarpc.com 
################################### */ 

function checkServer($server){ 

    //enter what email or emails (comma seperated) that should receive alerts if a server port isnt responding 
    $Email = "person@web_site.com, another_person@web_site.com"; 
     
    while (list($key,$port)=each($server[ports])) { 
        $alertEmail = 0; // 1=on, 0=off 

        $fp = fsockopen($server[ip], $port, &$errno, &$errstr, 4); 

        $serviceName = array( 
                "21"  =>"FTP      ", 
                "22"  =>"SSH      ", 
                "25"  =>"SMTP/Exim", 
                "53"  =>"BIND/DNS ", 
                "80"  =>"HTTP/DNS ", 
                "110" =>"POP3     ", 
                "3306"=>"MySQL    "); 

        if (!$fp) { 
            $data_p = "<td width=\"25\" align=\"center\"><img src=\"down.gif\"><!-- ($server[ip]:$port) --></td>"; 
            $alertEmail = 1; // 1=on, 0=off 
            $status_p = "$serviceName[$port]: DOWN <---\n"; 
        } else { 
            $data_p = "<td width=\"25\" align=\"center\"><img src=\"up.gif\"><!-- ($server[ip]:$port) --></td>"; 
            $status_p = "$serviceName[$port]: UP\n"; 
            fclose($fp); 
        } 
        $data .= $data_p; 
        $status .= $status_p; 
    } 

    if ($alertEmail) { 
            $today = date("m-d-Y H:m:s"); 
            $subject = "Server Alert! : $server[name]"; 
            $body  = "----------------------------------\n"; 
            $body .= "Server : $server[name]\n"; 
            $body .= "IP     : $server[ip]\n"; 
            $body .= "Time   : $today\n"; 
            $body .= "----------------------------------\n\n"; 
            $msg = $status.$body; 
            mail($Email, $subject, $msg); 
    } 

    return $data; 
} 
?> 
 
<table border="0" width="100%" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF"> 
   <tr bgcolor="#808080" style="font-weight:bold;color:#ffffff;"> 
        <td>Server Name</td> 
        <td>Info</td> 
        <td>Http</td> 
        <td>FTP</td> 
        <td>SSH</td> 
        <td>MySQL</td> 
        <td>Mail</td> 
    </tr> 
    <tr> 
        <td bgcolor="#c0c0c0">SERVERNAME</td> 
        <td align="center" bgcolor="#c0c0c0">INFO</td> 
<?php 
$server[ip] = "69.73.xxx.xxx"; //server ip of the machine being monitored 
$server[name] = "SERVERNAME"; //server hostname of the machine being monitored 
$server[ports] = array("80","21","22","3306","25"); //no need to alter these values unless you want to check different port numbers 
echo checkServer($server); 
?> 
    </tr> 
</table>

ripped from another site. must have sockets opened
 
Discord Verified
Its not working...
I get alot of code on the top like this...

"FTP ", "22" =>"SSH ", "25" =>"SMTP/Exim", "53" =>"BIND/DNS ", "80" =>"HTTP/DNS ", "110" =>"POP3 ", "3306"=>"MySQL "); if (!$fp) { $data_p = ""; $alertEmail = 1; // 1=on, 0=off $status_p = "$serviceName[$port]: DOWN <---\n"; } else { $data_p = ""; $status_p = "$serviceName[$port]: UP\n"; fclose($fp); } $data .= $data_p; $status .= $status_p; } if ($alertEmail) { $today = date("m-d-Y H:m:s"); $subject = "Server Alert! : $server[name]"; $body = "----------------------------------\n"; $body .= "Server : $server[name]\n"; $body .= "IP : $server[ip]\n"; $body .= "Time : $today\n"; $body .= "----------------------------------\n\n"; $msg = $status.$body; mail($Email, $subject, $msg); } return $data; } ?>
And it displays that...

Help please :)
 
that shouldnt work, what that code does is looks through the server to see if any ports are down that should be open for the server ie ftp, mysql, etc...

You are looking for server status, if its online or not, and for that you will need a list of the server addresses.

Code:
<html>

<head>
</head>
<body>
<?
function servstat($name, $host, $port) {
?>
<tr>
<td> <?echo($name); ?> </td>
<td> <?echo($host); ?> </td>
<td> <?echo($port); ?> </td>
<?
@$socket = fsockopen($host, $port,$errno,$errstr,5);
 if(!$socket) { 
  ?> <td> <b> <font color = "red"> Server Offline! </font> </b> </td><?
 } else { 
  fclose($socket); 
  ?> <td> <b> <font color = "green"> Server Online! </font> </b> </td><?
 } 
?> </tr> <?
}
?> <table border = "2">
<tr>
<td> Name </td>
<td> IP </td>
<td> Port </td>
<td> Status </td>
</tr> <?
servstat("halfscape", "halfscape.no-ip.org",43594);
servstat("the baj site", "bajsite.servebeer.com",8000);
// use the above example to enter more servers here!
?> </table>
<br> Code Written by: Night </br>
</body>
</html>

ok, there are a couple of problems with this though.... The more servers you add, the laggier it gets. Why? Becuase each time you visit this page, it gets you live status, and lags it down a lot! What you need to do is use cached data...

You need to look up cron jobs, and enter the status of the servers into a database and then use those status as a cache. With that you can also do server uptime, etc. Its not a complicated code to do, and seems fairly easy.
 
yes but how would i do that on like a smfforfree site? cause i have part of it but i want to add servers now.
 
Bakatool, don't reply to old topics.
 
Runescape Gamblingrunescape gambling
Back
Top