Hangwire Posted October 2, 2010 Share Posted October 2, 2010 Hi all! Yet again I have a problem. I really couldn't find what the heck's wrong with this thing. It's extremely simple and still... I'm trying to put a php script in my website to monitor the status of my FTP and HFS servers. Help? <TITLE>Server Status</TITLE> <?php $data .= " </div> <center> <div style=\"border-bottom:1px #999999 solid;width:480;\"><b> <font size='1' color='#3896CC'>Server Status</font></b> </div> </center> <br>"; //configure script $timeout = "1"; //set service checks $port[1] = "80"; $service[1] = "Apache"; $ip[1] = "localhost"; $icon[1] = "habbo.jpg"; $alt[1] = "Apache"; $port[2] = "8080"; $service[2] = "HFS Server"; $ip[2] = "localhost"; $icon[2] = "web.png"; $alt[2] = "HFS Server"; $port[3] = "21"; $service[3] = "FTP Server"; $ip[3] = "localhost"; $icon[3] = "web.png"; $alt[3] = "FTP Server"; // // NO NEED TO EDIT BEYOND HERE // UNLESS YOU WISH TO CHANGE STYLE OF RESULTS // //count arrays $ports = count($port); $ports = $ports + 1; $count = 1; //beggin table for status $data .= "<table width='480' border='1' cellspacing='0' cellpadding='3' style='border-collapse:none' bordercolor='#CCCCCC' align='center'>"; while($count < $ports){ if($ip[$count]==""){ $ip[$count] = "localhost"; } $fp = @fsockopen("$ip[$count]", $port[$count], $errno, $errstr, $timeout); if (!$fp) { $data .= "<tr><td width='18' align='center'><img src='http://127.0.0.1/stat/$icon[$count]' title='$alt[$count]' alt='$alt[$count]'></td><td>$service[$count]</td><td width='18' align='center'><img src='http://127.0.0.1/stat/off.png'></td></tr>"; } else { $data .= "<tr><td width='18' align='center'><img src='http://127.0.0.1/stat/$icon[$count]' title='$alt[$count]' alt='$alt[$count]'></td><td>$service[$count]</td><td width='18' align='center'><img src='http://127.0.0.1/stat/on.png'></td></tr>"; fclose($fp); } $count++; } //close table $data .= "</table><div>"; echo $data; ?> The output of this is... Parse error: syntax error, unexpected T_VARIABLE in D:\Program Files\xampp\xampp\htdocs\stat\server.php on line 18 Also, does somebody have a link or something to a tutorial/pre-made script (although I'd like to follow instructions about it) about server statistics? I want to have data on how much a certain partition on the server has free or full. Thank you in advance. Quote Link to comment https://forums.phpfreaks.com/topic/214957-script-problem-server-status/ Share on other sites More sharing options...
schilly Posted October 2, 2010 Share Posted October 2, 2010 hmmm can't see any errors but I did find this article: http://www.developertutorials.com/tutorials/php/port-scanning-and-service-status-checking-in-php-870/ Quote Link to comment https://forums.phpfreaks.com/topic/214957-script-problem-server-status/#findComment-1118181 Share on other sites More sharing options...
Hangwire Posted October 2, 2010 Author Share Posted October 2, 2010 Thank you for the quick reply! I took good look at what you gave me, I tried it, but again, to no avail. I added <?php include(server2.php); ?> on the place i needed it, but it doesn't show up, but when I open server2.php from the server I can see it works and displays everything properly. My server2.php (the script) is in the main directory of apache (htdocs). I also tried to put it in the folder of the current index im working on, but again - it doesn't work. Help? Quote Link to comment https://forums.phpfreaks.com/topic/214957-script-problem-server-status/#findComment-1118182 Share on other sites More sharing options...
Hangwire Posted October 2, 2010 Author Share Posted October 2, 2010 bump? Quote Link to comment https://forums.phpfreaks.com/topic/214957-script-problem-server-status/#findComment-1118256 Share on other sites More sharing options...
Hangwire Posted October 2, 2010 Author Share Posted October 2, 2010 Alright, well I've decided to let that old script go and try with this: <?php function check_port($port) { $conn = @fsockopen("127.0.0.1", $port, $errno, $errstr, 0.2); if ($conn) { fclose($conn); return true; } } function server_report() { $report = array(); $svcs = array('21'=>'FTP', '22'=>'SSH', '25'=>'SMTP', '80'=>'HTTP', '110'=>'POP3', '143'=>'IMAP', '3306'=>'MySQL'); foreach ($svcs as $port=>$service) { $report[$service] = check_port($port); } return $report; } $report = server_report(); ?> <table> <tr> <td>Service</td> <td>Status</td> </tr> <tr> <td>FTP</td> <td><?php echo $report['FTP'] ? "Online" : "Offline"; ?></td> </tr> <tr> <td>SSH</td> <td><?php echo $report['SSH'] ? "Online" : "Offline"; ?></td> </tr> <tr> <td>SMTP</td> <td><?php echo $report['SMTP'] ? "Online" : "Offline"; ?></td> </tr> <tr> <td>HTTP</td> <td><?php echo $report['HTTP'] ? "Online" : "Offline"; ?></td> </tr> <tr> <td>POP3</td> <td><?php echo $report['POP3'] ? "Online" : "Offline"; ?></td> </tr> <tr> <td>IMAP</td> <td><?php echo $report['IMAP'] ? "Online" : "Offline"; ?></td> </tr> <tr> <td>MySQL</td> <td><?php echo $report['MySQL'] ? "Online" : "Offline"; ?></td> </tr> </table> So far so good, it works like a charm on its own but I can't implement it into anything. For example, when I put <?php include("server2.php"); ?> In the right place on my website, it doesn't show anything. The script is in the same folder... Help? Quote Link to comment https://forums.phpfreaks.com/topic/214957-script-problem-server-status/#findComment-1118268 Share on other sites More sharing options...
schilly Posted October 3, 2010 Share Posted October 3, 2010 any errors when you include it? it looks ok. turn on full error reporting error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/214957-script-problem-server-status/#findComment-1118451 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.