We need a simple php script to display information from the game server like:

Server: 46.38.56.3:27015

Name: Army Ranks 1.3

Map: cs_assault

Players: 19/24

Status: On-line

There is a lot on the Internet, but I do not understand that they are not so spelled out as they all do not display information (Can anyone help? Ps just me for another game. Also their valve

<?php $server = '46.38.56.3'; $port = '27015'; function GetServerInfo($server,$port) { $fp = @fsockopen("udp://".$server, $port); if (!$fp) return false; @fwrite($fp,"\xFF\xFF\xFF\xFF\x54\x53\x6F\x75\x72\x63\x65\x20\x45\x6E\x67\x69\x6E\x65\x20\x51\x75\x65\x72\x79\x00".chr(10)); $start=time(); socket_set_timeout($fp,1); $st=fread($fp,1); $r=socket_get_status($fp); $result['status'] = $r["timed_out"]; $r=$r["unread_bytes"]; if ($r == 0) { @fclose($fp); return false;} $st.=fread($fp,$r); @fclose($fp); $st=substr($st,5); $address=SubStr($st,0,StrPos($st,chr(0))); $address=str_replace(chr(0),"|",$address); $st=SubStr($st,StrPos($st,chr(0))+1); $name=SubStr($st,0,StrPos($st,chr(0))); $st=SubStr($st,StrPos($st,chr(0))+1); $map=SubStr($st,0,StrPos($st,chr(0))); $st=SubStr($st,StrPos($st,chr(0))+1); $st=SubStr($st,StrPos($st,chr(0))+1); $st=SubStr($st,StrPos($st,chr(0))+1); $current=ord(SubStr($st,0,1)); $max=ord(SubStr($st,1,1)); if ($map == "") return false; $result['map'] = $map; $result['name']= $name; $result['current'] = $current; $result['max'] = $max; return $result; } $serv = GetServerInfo($server,$port); if ($serv) { echo ' Сервер: '.$server.':'.$port.' <br> Название: '.$serv['name'].' <br> Карта: '.$serv['map'].' <br> Игроков: '.$serv['current'].'/'.$serv['max'].' <br> Статус: On-line '; } else { echo 'Статус: Off-line'; } ?> 

  • here, according to your message, too few people understood anything. If you are using a finished product, then look for support forums. If you write your script, then lay out the code, links to the server API, and tell us what you can’t do. - teran
  • According to community rules, questions should not be reduced to completing tasks for students. Give an example of your implementation, add a description of the specific problems you have encountered. - Mikhail Vaysman
  • Updated post. Specifically, this code does not work for servers that are registered there. - Maxim Lysak
  • After if ($serv) { write echo var_dump($serv); and see what comes to you, in accordance with this output the necessary parameters $serv['<PARAMETER_NAME>'] - tCode

1 answer 1

You have GetServerInfo returns false , because if (!$fp) return false;

  • Just clean? - Maxim Lysak
  • @MaksimLysak why? - tCode