Малко помощ за поправка

b0nb0n40

Registered
Здравейте! Занчи искам във този код
Код:
<center>
<table border="1">
<tr>
<td> <font color="green"><b>Име</b></font> </td>
<td> <font color="green"><b>CLASSIC SERVER</b></font> </td>
</tr>
<tr>
<td> <font color="green"><b>IP + Port</b></font> </td>
<td> <font color="green"><b>77.77.77.77:27015</b></font> </td>
</tr>
<tr>
<td> <font color="green"><b>Карта</b></font> </td>
<td> <font color="green"><b>de_dust2</b></font> </td>
</tr>
<tr>
<td> <font color="green"><b>Играчи</b></font> </td>
<td> <font color="green"><b>14/20</b></font> </td>
</tr>
<tr>
<td> <font color="green"><b>Статус</b></font> </td>
<td> <font color="green"><b>Online / <font color="red">Offline</font></b></font> </td>
</tr>
</table> 
</center>

Да вмъкнете
inc.php

Цитат:
<?php
class serverinfo
{
var $ip;
var $port;

var $fp;
var $timeout;

var $serverData;
var $playerData;


function serverinfo($ip, $port, $timeout = 3)
{
$this->ip = $ip;
$this->port = $port;

$this->fp = fsockopen("udp://" . $ip, $port);
$this->timeout = $timeout;
}


function getServerData()
{
$this->writeData($this->getQuery("A2S_INFO"));

$this->getData("byte");
$this->getString();
$this->serverData['hostname'] = $this->getString();
$this->serverData['map'] = $this->getString();
$this->getString();
$this->serverData['mod'] = $this->getString();
$this->serverData['players'] = $this->getData("byte");
$this->serverData['maxplayers'] = $this->getData("byte");
$this->getData("byte");
$this->serverData['servertype'] = (chr($this->getData("byte")) == "d") ? "Dedicated" : "Listen";
$this->serverData['server_os'] = (chr($this->getData("byte")) == "w") ? "Windows" : "Linux";
$this->serverData['password'] = $this->getData("byte");
$this->getData("byte");
$this->getString();
$this->getString();
$this->getString();
$this->getData("long");
$this->getData("long");
$this->getData("byte");
$this->getData("byte");
$this->serverData['vac'] = $this->getData("byte");
$this->getData("byte");
}


function getPlayerData()
{
$this->writeData($this->getQuery("A2S_PLAYER"));

fread($this->fp, 4);
$this->getData("byte");

$count = $this->getData("byte");

for($i = 0; $i < $count; $i++)
{
$this->playerData[$i]['id'] = $this->getData("byte");
$this->playerData[$i]['name'] = $this->getString();
$this->playerData[$i]['frags'] = $this->getData("long");
$this->playerData[$i]['time'] = round($this->getData("float"));
}
}


function getQuery($queryType)
{
switch($queryType)
{
case "A2S_SERVERQUERY_GETCHALLENGE":
return "\xFF\xFF\xFF\xFF\x57";
break;

case "A2S_INFO":
return "\xFF\xFF\xFF\xFFTSource Engine Query\x00";
break;

case "A2S_PLAYER":
return sprintf("\xFF\xFF\xFF\xFFU%s", $this->getChallenge());
break;
}
}


function getChallenge()
{
$this->writeData($this->getQuery("A2S_SERVERQUERY_GETCHALLENGE"));

return substr(fread($this->fp, 16), 5, 9);
}


function getData($type)
{
switch($type)
{
case "long":
$data = unpack("L", fread($this->fp, 4));
return $data[1];
break;

case "byte":
return ord(fread($this->fp, 1));
break;

case "char":
return fread($this->fp, 1);
break;

case "float":
$data = unpack("f", fread($this->fp, 4));
return $data[1];
break;
}
}


function getString()
{
$string = '';
$loop = TRUE;

while($loop)
{
$_fp = $this->getData("char");

if( ord($_fp) != 0 )
{
$string .= $_fp;
}
else { $loop = FALSE; }
}

return $string;
}


function writeData($input)
{
if( !$this->fp )
{
exit("Error: Couldn't connect to server.");
}
else {
fwrite($this->fp, $input);
socket_set_timeout($this->fp, $this->timeout);
}
}


function setTimeFormat($format, $input)
{
$hours = floor($input / 3600);
$input = $input % 3600;

$minutes = floor($input / 60);
$input = $input % 60;

$seconds = round($input);

return sprintf($format, $hours, $minutes, $seconds);
}


function sortPlayers($sort = "time", $type = "desc")
{
if(isset($this->playerData[0][$sort]))
{
for($i = 0; $i < count($this->playerData); $i++)
{
$temp[] = $this->playerData[$i][$sort];
}

switch($sort)
{
case "name":
uasort($temp, "strcasecmp");
break;

default:
if($type == "desc") {
arsort($temp);
}
elseif($type == "asc") {
asort($temp);
}
break;
}

foreach($temp as $key => $value)
{
$keys[] = $key;
}

foreach($keys AS $k => $v)
{
$tempvar[$k]['id'] = $this->playerData[$v]['id'];
$tempvar[$k]['name'] = $this->playerData[$v]['name'];
$tempvar[$k]['frags'] = $this->playerData[$v]['frags'];
$tempvar[$k]['time'] = $this->playerData[$v]['time'];
}

$this->playerData = $tempvar;
}
}

function getStatus() {
$status = @fsockopen($ip, $port, $errno, $errstr, 3);
if (!$status) {
return 1;
} else {
return 0;
}
}
}
?>


index.php
Цитат:
<?php
header("Content-type: image/png; charset=windows-1251");
require_once("inc.php");
$ip_port = array(
1 => "cs2.cs-plovdiv.info:27015" //Тук пишеш IP адресът и портът
);

$rand = rand(1, count($ip_port));
$getip_port = explode(":", $ip_port[$rand]);

$ip = $getip_port[0];
$port = $getip_port[1];

$s = &new serverinfo($ip, $port);
$s->getServerData();
$players = $s->serverData['players']; //Броя на играчите
$maxplayers = $s->serverData['maxplayers']; //Максималния брой на играчи
$map = $s->serverData['map']; //Картата


$image = imagecreatefrompng("background.png"); //Тук пишеш пътя до картинката за фон. Хубаво е да е в същата папка или поне на същия сървър
$black = imagecolorallocate($image, 0, 0, 0); //Създаваме черен цвят
$red = imagecolorallocate($image, 255, 0, 0); //Създаваме червен цвят
$green = imagecolorallocate($image, 0, 255, 0); //Създаваме зелен цвят
$fontsize = 3; //Може да бъде число от 1 до 5. Определя големината на шрифта

imagestring($image, $fontsize, 10, 10, "Players: " . $players ." / ".$maxplayers, $black); //x = 10, y = 10
imagestring($image, $fontsize, 10, 30, "Server: " . $ip_port[1], $black); //x = 10, y = 30
imagestring($image, $fontsize, 10, 50, "Map: " . $map, $black); //x = 10, y = 50
if($s->getStatus()) {
imagestring($image, $fontsize, 10, 70, "Server is ", $black); //x = 10, y = 70
imagestring($image, $fontsize, 80, 70, "Online", $green); //x = 80, y = 70
} else {
imagestring($image, $fontsize, 10, 70, "Server is ", $black); //x = 10, y = 70
imagestring($image, $fotnsize, 80, 70, "Offline", $red); //x = 80, y = 70
}

imagepng($image);
imagedestroy($image);
?>

Само че да не се променя картинка а текста в таблицата
Благодаря предварително!
 
Код:
<?php
header("Content-type: image/png; charset=windows-1251");  
class serverinfo 
{ 
var $ip; 
var $port; 

var $fp; 
var $timeout; 

var $serverData; 
var $playerData; 


function serverinfo($ip, $port, $timeout = 3) 
{ 
$this->ip = $ip; 
$this->port = $port; 

$this->fp = fsockopen("udp://" . $ip, $port); 
$this->timeout = $timeout; 
} 


function getServerData() 
{ 
$this->writeData($this->getQuery("A2S_INFO")); 

$this->getData("byte"); 
$this->getString(); 
$this->serverData['hostname'] = $this->getString(); 
$this->serverData['map'] = $this->getString(); 
$this->getString(); 
$this->serverData['mod'] = $this->getString(); 
$this->serverData['players'] = $this->getData("byte"); 
$this->serverData['maxplayers'] = $this->getData("byte"); 
$this->getData("byte"); 
$this->serverData['servertype'] = (chr($this->getData("byte")) == "d") ? "Dedicated" : "Listen"; 
$this->serverData['server_os'] = (chr($this->getData("byte")) == "w") ? "Windows" : "Linux"; 
$this->serverData['password'] = $this->getData("byte"); 
$this->getData("byte"); 
$this->getString(); 
$this->getString(); 
$this->getString(); 
$this->getData("long"); 
$this->getData("long"); 
$this->getData("byte"); 
$this->getData("byte"); 
$this->serverData['vac'] = $this->getData("byte"); 
$this->getData("byte"); 
} 


function getPlayerData() 
{ 
$this->writeData($this->getQuery("A2S_PLAYER")); 

fread($this->fp, 4); 
$this->getData("byte"); 

$count = $this->getData("byte"); 

for($i = 0; $i < $count; $i++) 
{ 
$this->playerData[$i]['id'] = $this->getData("byte"); 
$this->playerData[$i]['name'] = $this->getString(); 
$this->playerData[$i]['frags'] = $this->getData("long"); 
$this->playerData[$i]['time'] = round($this->getData("float")); 
} 
} 


function getQuery($queryType) 
{ 
switch($queryType) 
{ 
case "A2S_SERVERQUERY_GETCHALLENGE": 
return "\xFF\xFF\xFF\xFF\x57"; 
break; 

case "A2S_INFO": 
return "\xFF\xFF\xFF\xFFTSource Engine Query\x00"; 
break; 

case "A2S_PLAYER": 
return sprintf("\xFF\xFF\xFF\xFFU%s", $this->getChallenge()); 
break; 
} 
} 


function getChallenge() 
{ 
$this->writeData($this->getQuery("A2S_SERVERQUERY_GETCHALLENGE")); 

return substr(fread($this->fp, 16), 5, 9); 
} 


function getData($type) 
{ 
switch($type) 
{ 
case "long": 
$data = unpack("L", fread($this->fp, 4)); 
return $data[1]; 
break; 

case "byte": 
return ord(fread($this->fp, 1)); 
break; 

case "char": 
return fread($this->fp, 1); 
break; 

case "float": 
$data = unpack("f", fread($this->fp, 4)); 
return $data[1]; 
break; 
} 
} 


function getString() 
{ 
$string = ''; 
$loop = TRUE; 

while($loop) 
{ 
$_fp = $this->getData("char"); 

if( ord($_fp) != 0 ) 
{ 
$string .= $_fp; 
} 
else { $loop = FALSE; } 
} 

return $string; 
} 


function writeData($input) 
{ 
if( !$this->fp ) 
{ 
exit("Error: Couldn't connect to server."); 
} 
else { 
fwrite($this->fp, $input); 
socket_set_timeout($this->fp, $this->timeout); 
} 
} 


function setTimeFormat($format, $input) 
{ 
$hours = floor($input / 3600); 
$input = $input % 3600; 

$minutes = floor($input / 60); 
$input = $input % 60; 

$seconds = round($input); 

return sprintf($format, $hours, $minutes, $seconds); 
} 


function sortPlayers($sort = "time", $type = "desc") 
{ 
if(isset($this->playerData[0][$sort])) 
{ 
for($i = 0; $i < count($this->playerData); $i++) 
{ 
$temp[] = $this->playerData[$i][$sort]; 
} 

switch($sort) 
{ 
case "name": 
uasort($temp, "strcasecmp"); 
break; 

default: 
if($type == "desc") { 
arsort($temp); 
} 
elseif($type == "asc") { 
asort($temp); 
} 
break; 
} 

foreach($temp as $key => $value) 
{ 
$keys[] = $key; 
} 

foreach($keys AS $k => $v) 
{ 
$tempvar[$k]['id'] = $this->playerData[$v]['id']; 
$tempvar[$k]['name'] = $this->playerData[$v]['name']; 
$tempvar[$k]['frags'] = $this->playerData[$v]['frags']; 
$tempvar[$k]['time'] = $this->playerData[$v]['time']; 
} 

$this->playerData = $tempvar; 
} 
} 

function getStatus() { 
$status = @fsockopen($ip, $port, $errno, $errstr, 3); 
if (!$status) { 
return 1; 
} else { 
return 0; 
} 
} 
} 
$ip_port = array( 
1 => "cs2.cs-plovdiv.info:27015" //Тук пишеш IP адресът и портът 
); 

$rand = rand(1, count($ip_port)); 
$getip_port = explode(":", $ip_port[$rand]); 

$ip = $getip_port[0]; 
$port = $getip_port[1]; 

$s = &new serverinfo($ip, $port); 
$s->getServerData(); 
$players = $s->serverData['players']; //Броя на играчите 
$maxplayers = $s->serverData['maxplayers']; //Максималния брой на играчи 
$map = $s->serverData['map']; //Картата 
$hostname = $s->serverData['hostname']; //Името на сървъра
$line="";
if($s->getStatus()) { 
$line="Online";
} else { 
$line="Offline";
}
?>
<center> 
<table border="1"> 
<tr> 
<td> <font color="green"><b>Име</b></font> </td> 
<td> <font color="green"><b><?php echo $hostname; ?></b></font> </td> 
</tr> 
<tr> 
<td> <font color="green"><b>IP + Port</b></font> </td> 
<td> <font color="green"><b><?php echo $ip.":".$port; ?></b></font> </td> 
</tr> 
<tr> 
<td> <font color="green"><b>Карта</b></font> </td> 
<td> <font color="green"><b><?php echo $map; ?></b></font> </td> 
</tr> 
<tr> 
<td> <font color="green"><b>Играчи</b></font> </td> 
<td> <font color="green"><b><?php echo $players."/".$maxplayers; ?></b></font> </td> 
</tr> 
<tr> 
<td> <font color="green"><b>Статус</b></font> </td> 
<?php if($line="Online") { ?>
<td> <font color="green"><b>Online</b></font> </td> 
<?php } else { ?>
<td><font color="red"><b>Offline</b></font></td>
<?php } ?>
</tr> 
</table> 
</center>
така работи ли?
 
Ако оправиш и тази грешка
Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\G06k0\cs\index1.php:2) in C:\AppServ\www\G06k0\cs\index1.php on line 3

Получаваш +1 от мене


P.S. Грешката идва от тук
header("Content-type: image/png; charset=windows-1251");

Поправя се на text/html
Оправих се +1 ти давам
Ако искаш още +1 ми пиши ЛС
 

Back
Горе