检查游戏服务器是否在线的PHP代码


PHP code to check if game server is online

我正试图在我的网站上为我的游戏服务器制作一条状态消息。如果它是在线的,它应该说"在线"等等。

这是我现在的代码:

<?php
$site = '217.78.24.5';
$port = '28728';
$check = fsockopen( "$site", "$port", $errno, $errstr, 6 );
if ( ! $check ){ echo 'Offline';
}
else{ echo 'Online (YAY)';}
?>

但出于某种原因,它一直在离线告诉我
游戏是CS:GO,如果它很重要的话

您的问题将出现在$errno和$errstr中,请编辑您的代码:

$debug = true;
$site = '217.78.24.5';
$port = '28728';
$check = fsockopen( $site, $port, $errno, $errstr, 6 );
if ( ! $check ) {
   if($debug){
      echo "Error #$errno : $errstr <br>";
   } 
   echo 'Offline';     
}
else { 
   echo 'Online (YAY)';
}

如果你看到:

错误#13:权限被拒绝

也许是你的防火墙。