Ok mam takie cos :
class.php
<?php
class SAMPQueryScript {
var $ip;
var $port;
var $connection;
var $enabled = false;
var $timeout;
var $serverData;
var $playerData;
var $error = "Unknown error";
function SAMPQueryScript($ip, $port, $timeout=1) {
$this->ip = $this->verifyHost($ip);
if ($this->ip === FALSE) {
$this->error = "Could not resolve host name";
return;
}
$this->port = $port;
$this->timeout = $timeout*100;
$this->enabled = true;
$this->error = false;
}
function queryServer() {
if (!$this->enabled) return false;
if ($this->establishConnection() === FALSE) return false;
$this->sendPacket("i");
$this->captureServerData();
if (empty($this->error)) { $this->sendPacket("c");
}
return true;
}
function establishConnection() {
$errno = $errstr = 0;
$this->connection = @fsockopen("udp://".$this->ip, $this->port, $errno, $errstr, $this->timeout/1000000
); if (!$this->connection) {
$this->error = $errstr;
return false;
}
else {
return true;
}
}
function captureServerData() {
$firstData = fread($this->connection, 4
); $this->error = "Brak graczy na serwie";
return false;
}
if ($firstData != "SAMP") {
$this->error = "Unidentified response";
return false;
}
return true;
}
function readNextSize($sizeLength) {
$nextLength = ord
(fread($this->connection, $sizeLength)); if ($nextLength > 0
) return fread($this->connection, $nextLength); else return "";
}
function sendPacket($packetType="i") {
// compile the packet
$packet = "SAMP";
$ipChunks = explode(".", $this->ip); foreach($ipChunks as $k => $v) {
$packet .= chr($v);
}
$packet .= chr($this->port & 0xFF);
$packet .= chr($this->port >> 8 & 0xFF).$packetType;
// send the packet
}
function verifyHost($ip) {
// verify ip address
if (($longip = ip2long($ip)) !== FALSE && ($ip == long2ip($longip))) return $ip; else {
$newIp = gethostbyname($ip);
if ($newIp == $ip) return false;
else return $newIp;
}
}
}
?>
i 2 plik index.php:
<?
require "class.php";
$ip = "87.230.77.126";
$port = "7070";
$query = new SAMPQueryScript($ip, $port);
$query->queryServer();
if ($query->error) {
} else {
}
?>
i to działa

Ale ma pytanie czy da sie jakos skrócić ten skrypt ? a dokladnie plik class. php ?