Skip to content

Instantly share code, notes, and snippets.

@pedropapa
Created November 25, 2014 18:39
Show Gist options
  • Save pedropapa/a7438ff7a7966deb7be1 to your computer and use it in GitHub Desktop.
Save pedropapa/a7438ff7a7966deb7be1 to your computer and use it in GitHub Desktop.
Buscar jogadores e servidores online no SA-MP
<?php
function Request($a, $b, $c, $d, $e) {
$ch = curl_init();
$exec = curl_setopt_array($ch, array(
CURLOPT_URL => $a,
CURLOPT_RETURNTRANSFER => $b,
CURLOPT_HEADER => 1,
CURLOPT_NOBODY => 0,
CURLOPT_COOKIE => $c,
CURLOPT_CUSTOMREQUEST => ($d)?"POST":"GET",
CURLOPT_POSTFIELDS => $d,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_TIMEOUT => 6,
CURLOPT_REFERER => $e
)
);
return array(
"data" => explode("\r\n\r\n", curl_exec($ch), 3),
"httpcode" => (int)curl_getinfo($ch, CURLINFO_HTTP_CODE)
);
}
$request = Request("http://sa-mp.com/", 1, null, false, null, null);
preg_match('/players.online.*?>(\d+)</i', $request["data"][1], $playersOnline);
preg_match('/servers.online.*?>(\d+)</i', $request["data"][1], $serversOnline);
echo "Jogadores online: ".$playersOnline[1].", servidores online: ". $serversOnline[1];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment