Getting information from a Text File
Posted: Sun Aug 24, 2008 12:39 am
Alright i have this working 100%
http://sampbrowser.hostwebsfree.com/test.php
But How can skip an unresponsive server IP and go to the next line in the .txt
Part of the code is here
Thanks for you PHP developers who help
http://sampbrowser.hostwebsfree.com/test.php
But How can skip an unresponsive server IP and go to the next line in the .txt
Part of the code is here
Code: Select all
$handle = fopen("http://sampbrowser.hostwebsfree.com/Servers.txt", "r");
?>
<table width="701" border="0" bordercolor="#000000">
<tr>
<td bgcolor="#2B5486">Hostname:</td>
<td bgcolor="#2B5486">Players:</td>
<td bgcolor="#2B5486">Gamemode:</td>
<td bgcolor="#2B5486">Password:</td>
</tr>
<?php
while (!feof($handle))
{
$Data = fgets($handle);
$IP = split("[ ]+", $Data);
$Loop = count($IP);
for($i=0;$i<$Loop;$i++)
{
$DATOS = split(":", $IP[$i]);
$Ipx = $DATOS[0];
$Portx = $DATOS[1];
////// COMIENZO SCRIPT QUERY ///////
$ip = $Ipx;
$port = $Portx;
$fp = fsockopen('udp://' . $ip, $port, $errno, $errstr);
if (!$fp)
{
echo "<tr><td bgcolor=\"#2B5486\">Socket Error: $errno - $errstr</td></tr>\n";
}
else
{
$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.'i');
fread($fp, 11);
$is_passworded = ord(fread($fp, 1));
$plr_count = ord(fread($fp, 2));
$max_plrs = ord(fread($fp, 2));
$strlen = ord(fread($fp, 4));
$hostname = fread($fp, $strlen);
$strlen = ord(fread($fp, 4));
$gamemode = fread($fp, $strlen);
$strlen = ord(fread($fp, 4));
$mapname = fread($fp, $strlen);
echo ' <tr><td bgcolor="#2B5486" colspan="1" align="center"><b>' . $hostname . '</b></td>'."\n";
echo ' <td bgcolor="#2B5486" width="100">' . $plr_count . ' / ' . $max_plrs . '</td>'."\n";
echo ' <td bgcolor="#2B5486">' . $gamemode . '</td>'."\n";
//echo ' <td bgcolor="#2B5486">MapName: </td><td bgcolor="#2B5486">' . $mapname . '</td></tr>'."\n";
if ($is_passworded)
{
echo ' <td bgcolor="#2B5486">Yes</td>'."\n";
} else {
echo ' <td bgcolor="#2B5486">No</td></tr>'."\n";
}
fwrite($fp, $packet.'c');