Jump to content

Server Status Checker Help :(


Username:

Recommended Posts

I'm making a server status checker for a game, and it mostly works. But, it always displays as offline. Here is my code.

 

<?php	
     $status = GetServerStatus('24.68.198.193',43594); // IP or Hostname Goes Here
     function GetServerStatus($site, $port) {
          $fp = @fsockopen($site, $port, $errno, $errstr, 2);
          if (!$fp) { 
               $imagepath="off.png"; //OFFLINE IMAGE LINK!
               $image=imagecreatefrompng($imagepath);
               header('Content-Type: image/png');
               imagepng($image);
          } else { //ONLINE Status
               $imagepath="on.png"; //ONLINE IMAGE LINK!
               $image=imagecreatefrompng($imagepath);
               header('Content-Type: image/png');
               imagepng($image);
          }
     }
?>

 

 

I made sure 43594 port was open and that the IP was correct

http://www.dcfilms.org/status.php

 

Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/206989-server-status-checker-help/
Share on other sites

Just move the call to your function under the actual function:

 

<?php
     function GetServerStatus($site, $port) {
          $fp = @fsockopen($site, $port, $errno, $errstr, 2);
          if (!$fp) { 
               $imagepath="off.png"; //OFFLINE IMAGE LINK!
               $image=imagecreatefrompng($imagepath);
               header('Content-Type: image/png');
               imagepng($image);
          } else { //ONLINE Status
               $imagepath="on.png"; //ONLINE IMAGE LINK!
               $image=imagecreatefrompng($imagepath);
               header('Content-Type: image/png');
               imagepng($image);
          }
     }
     $status = GetServerStatus('24.68.198.193',43594); // IP or Hostname Goes Here
?>

Just move the call to your function under the actual function:

 

<?php
     function GetServerStatus($site, $port) {
          $fp = @fsockopen($site, $port, $errno, $errstr, 2);
          if (!$fp) { 
               $imagepath="off.png"; //OFFLINE IMAGE LINK!
               $image=imagecreatefrompng($imagepath);
               header('Content-Type: image/png');
               imagepng($image);
          } else { //ONLINE Status
               $imagepath="on.png"; //ONLINE IMAGE LINK!
               $image=imagecreatefrompng($imagepath);
               header('Content-Type: image/png');
               imagepng($image);
          }
     }
     $status = GetServerStatus('24.68.198.193',43594); // IP or Hostname Goes Here
?>

I'm doing my best not to come off as stupid, but this code still doesn't work and I think this may be to my host using a firewall.

 

...Or me being tired.

Remove the "@" before the fsockopen call and see if it's generating any errors.

"The image “http://statuschecker.comule.com/status.php” cannot be displayed, because it contains errors."

And again, it displays, ONLY online again.

 

EDIT:

I changed the permissions to 777 and now it only displays "Online"

 

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.