26.04.2016, 17:53
I look at a site php, to tell me a bit about the "function" and the "return" so I created two page, test and b.php
in test.php
and in b.php
the problem is always the same, when I put return 1;
he shows me in the page
and when I put return $data;
he shows me in the page
I try to understand this https://sampforum.blast.hk/showthread.php?tid=407156
in test.php
PHP код:
<?php
include("b.php");
for ($i=0;$i<$count;$i++)
{
echo "player: ".$data[$i]['player'].", <strong>score</strong> ".$data[$i]['score']."<br>";
}
$data = GetPlayers("51.254.29.46", "30465");
$count = count($data);
for ($i=0;$i<$count;$i++) {
echo "player: ".$data[$i]['player'].", <strong>score</strong> ".$data[$i]['score']."<br>";
}
?>
PHP код:
<?php
function GetPlayers($server_ip, $server_port) {
$fp = fsockopen('udp://'.$server_ip, $server_port, $errno, $errstr);
stream_set_timeout($fp, 5);
if (!$fp) return false;
$packet = 'SAMP';
$packet .= chr(strtok($ip, '.'));
$packet .= chr(strtok('.'));
$packet .= chr(strtok('.'));
$packet .= chr(strtok('.'));
$packet .= chr($port & 0xFF);
$packet .= chr($port >> 8 & 0xFF);
fwrite($fp, $packet.'c');
fread($fp, 11);
$players = ord(fread($fp, 2));
$start = 0;
if ($players > 0) {
for ($i=0;$i<$players;$i++) {
$strlen = ord(fread($fp, 1));
$player = fread($fp, $strlen);
$score = ord(fread($fp, 4));
$data[$start]['player'] = $player;
$data[$start]['score'] = $score;
$start++;
}
}
fclose($fp);
return 1;
}
?>
he shows me in the page
and when I put return $data;
he shows me in the page
I try to understand this https://sampforum.blast.hk/showthread.php?tid=407156