<?php
$ip = "5.135.179.10:27776";
?>
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  <style>
    body {
      margin: 0;
      padding: 0;
    }

    #container {
      width: 100%;
      height: 100%;

      position: fixed;
      left: 0px;
      top: 0px;
      z-index: -1;
    }

    img {
      width: 100%;
      height: 100%;
    }
  </style>
</head>
<body>
  <div id="container">
<?
  /* SOURCE ENGINE QUERY FUNCTION, requires the server ip:port */
function source_query($ip)
{
$cut = explode(":", $ip);
$HL2_address = $cut[0];
$HL2_port = $cut[1];

$HL2_command = "\377\377\377\377TSource Engine Query\0";
$HL2_socket = fsockopen("udp://".$HL2_address, $HL2_port, $errno, $errstr,3);
fwrite($HL2_socket, $HL2_command); $JunkHead = fread($HL2_socket,4);
$CheckStatus = socket_get_status($HL2_socket);

if($CheckStatus["unread_bytes"] == 0)
{
    return 0;
}

$do = 1;
while($do)
{
    $str = fread($HL2_socket,1);
    $HL2_stats.= $str;
    $status = socket_get_status($HL2_socket);
    if($status["unread_bytes"] == 0)
    {
        $do = 0;
    }
}
fclose($HL2_socket);

$x = 0;
while ($x <= strlen($HL2_stats))
{
    $x++;
    $result.= substr($HL2_stats, $x, 1);    
}
$result = urlencode($result); // the output
return $result;
} 
/* FORMAT SOURCE ENGINE QUERY (assumes the query's results were urlencode()'ed!) */
function format_source_query($string)
{
$string = str_replace('%07','',$string);
$string = str_replace("%00","|||",$string);
$sinfo = urldecode($string);
$sinfo = explode('|||',$sinfo);
$info['hostname'] = $sinfo[0];
$info['map'] = $sinfo[1];
$info['game'] = $sinfo[2];
if ($info['game'] == 'garrysmod') { $info['game'] = "Garry's Mod"; }
elseif ($info['game'] == 'cstrike') { $info['game'] = "Counter-Strike: Source"; }
elseif ($info['game'] == 'dod') { $info['game'] = "Day of Defeat: Source"; }
$info['gamemode'] = $sinfo[3];
return $info;
}
$query = source_query($ip); // $ip MUST contain IP:PORT
$q = format_source_query($query);

if (file_exists("images/".$q['map'])) {
echo '<img src="images/'.$q['map'].'">';
} else {
echo '<img src="images/mg.png">';
}
?>
 </div>
</body>
</html>