Username: Posted July 7, 2010 Share Posted July 7, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/206989-server-status-checker-help/ Share on other sites More sharing options...
Adam Posted July 7, 2010 Share Posted July 7, 2010 You need to call the function after you define it. Quote Link to comment https://forums.phpfreaks.com/topic/206989-server-status-checker-help/#findComment-1082366 Share on other sites More sharing options...
Username: Posted July 7, 2010 Author Share Posted July 7, 2010 You need to call the function after you define it. Can you give me an example to this? I'm still not really there for PHP. Quote Link to comment https://forums.phpfreaks.com/topic/206989-server-status-checker-help/#findComment-1082543 Share on other sites More sharing options...
Adam Posted July 7, 2010 Share Posted July 7, 2010 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/206989-server-status-checker-help/#findComment-1082544 Share on other sites More sharing options...
Username: Posted July 7, 2010 Author Share Posted July 7, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/206989-server-status-checker-help/#findComment-1082553 Share on other sites More sharing options...
Username: Posted July 7, 2010 Author Share Posted July 7, 2010 I moved to a different host and now it only displays as online.... http://dcfilms.110mb.com/index.php Quote Link to comment https://forums.phpfreaks.com/topic/206989-server-status-checker-help/#findComment-1082565 Share on other sites More sharing options...
Adam Posted July 7, 2010 Share Posted July 7, 2010 Remove the "@" before the fsockopen call and see if it's generating any errors. Quote Link to comment https://forums.phpfreaks.com/topic/206989-server-status-checker-help/#findComment-1082567 Share on other sites More sharing options...
Username: Posted July 7, 2010 Author Share Posted July 7, 2010 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" Quote Link to comment https://forums.phpfreaks.com/topic/206989-server-status-checker-help/#findComment-1082577 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.