Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php][mysql] Lista OTS
Forum PHP.pl > Forum > Przedszkole
-Adriannek-
  1. <?php
  2.  
  3. /*laczysz sie, wybierasz baze*/
  4.  mysql_connect(localhost,root,pas);
  5.  if(isset($_GET['id'])) //jesli istnieje zmienna $_GET czyli ?id=
  6. {
  7. $id = intval($_GET['id']); //przypisanie + filtracja int
  8.  /*pobierasz rekordy , czyli tworzysz zapytanie SQL z warunkiem WHERE */
  9.  
  10.  $sql = mysql_query("SELECT id,ip,port,nazwa,client,loncze,acc,opis FROM ots WHERE id = '$id' ");
  11. $rekord=mysql_fetch_array($sql);
  12.  
  13. echo 'Nazwa: ';
  14. echo "<strong>".$rekord['nazwa']."</strong><br>";//wyswietlasz rekordy o podanym ID
  15. echo 'Ip/Host: ';
  16. echo "<strong>".$rekord['ip']."</strong><br>";
  17. echo 'Acc: ';
  18. echo "<strong>".$rekord['acc']."</strong><br>";
  19. echo 'Port: ';
  20. echo "<strong>".$rekord['port']."</strong><br>";
  21. echo 'Klient: ';
  22. echo "<strong>".$rekord['client']."</strong><br>";
  23. echo 'Łoncze: ';
  24. echo "<strong>".$rekord['loncze']."</strong><br><hr />";
  25. echo '<left>Opis Serwera: </left><br>';
  26. echo "<strong>".$rekord['opis']."</strong><br><hr />";
  27.  
  28.  
  29.  
  30.  
  31. echo 'Status Serwera:<br>';
  32.  
  33.  
  34.  
  35.  
  36.  
  37. }
  38. ?>

Ten skrypt wyświetla szczegóły rekordów po danym id i chce żeby też sprawdzał status serwera i zapisywał największa ilość graczy online,
czy ktoś mógł by mi to przerobić?
A tutaj daje 2 skrypty na status serwera:
  1. <?php
  2.  
  3. //======================================================== 
  4. // Author: DeathfireD with help on regex from 
  5. // epimeth, weedpacket, and bradgrafelman 
  6. // Date: June 30, 2006 
  7. // 
  8. // Desc: Tutorial on how to get OTserv info using regex 
  9. // (preg_match) 
  10. //======================================================== 
  11. //server packet that needs to be sent to get info 
  12. $info = chr(6).chr(0).chr(255).chr(255).'info'; 
  13. //making socket connection to an ip and port 7171 
  14. $sock = @fsockopen(armia.toproste.pl, 7171, $errno, $errstr, 1); 
  15.  
  16. //show source request 
  17. if($_REQUEST['action']=='source'){ 
  18. highlight_file(__FILE__); 
  19. } 
  20. else{ 
  21. if ($sock) 
  22. { 
  23. //writes the info gotten by sending the server packet. 
  24. fwrite($sock, $info); 
  25. $data=''; 
  26.  
  27. while (!feof($sock)) 
  28. { 
  29. $data .= fgets($sock, 1024); 
  30. } 
  31. fclose($sock); 
  32.  
  33. //players online and max (ex. Players online: 24 / 100) 
  34. preg_match('/players online="(d+)" max="(d+)"/', $data, $matches); 
  35. echo '<p>Status:<b><font color="#00FF00"> Online</font></b>'; 
  36. echo '<br />Players online: '.$matches[1].' / '.$matches[2]; 
  37.  
  38.  
  39. //Monster total (ex. Monsters: 23456) 
  40. preg_match('/monsters total="(d+)"/', $data, $matches); 
  41. print '<br />Monsters: '.$matches[1].''; 
  42.  
  43. //Uptime (Uptime: 23h 12m) 
  44. preg_match('/uptime="(d+)"/', $data, $matches); 
  45. $h = floor($matches[1] / 3600); 
  46. $m = floor(($matches[1] - $h*3600) / 60); 
  47.  
  48. echo '<br />Uptime: '.$h.'h '.$m.'m'.'</p>'; 
  49. echo ' <ul>
  50. <li><a href="info.php?act=onlinelist">Online List</a></li>
  51. </ul>';
  52. } 
  53. else 
  54. { 
  55. echo '<p>Server Status:<b><font color="#FF0000"> Offline</font></b></p>'; 
  56. } 
  57. } 
  58. ?>

  1. <?php
  2. $info = chr(6).chr(0).chr(255).chr(255).'info';
  3. $sock = @fsockopen($ip, $port, $errno, $errstr, 1);
  4.  
  5. if ($sock)
  6. {
  7. fwrite($sock, $info);
  8. $data='';
  9.  
  10. while (!feof($sock))
  11. $data .= fgets($sock, 1024);
  12. fclose($sock);
  13.  
  14. preg_match('/players online="(d+)" max="(d+)" peak="(d+)"/', $data, $matches);
  15. print '<div style="font-size: 13; font-weight: bold; color: green">ONLINE</div>';
  16. print '<div style="font-size: 11; font-weight: normal; color: white">Graczy: ';
  17. print $matches[1] . '/' . $matches[2];
  18.  
  19. preg_match('/uptime="(d+)"/', $data, $matches);
  20. $h = floor($matches[1] / 3600);
  21. $m = floor(($matches[1] - $h*3600) / 60);
  22.  
  23. print "<br>Uptime: $h " . ($h==1'godzina' : ($h==2||$h==3||$h==4'godziny' : 'godzin'));
  24. print " $m " . ($m==1'minuta' : ($m==12||$m==13||$m==14'minut' : ($m%10==2||$m%10==3||$m%10==4'minuty' : 'minut'))) . '</div>';
  25. }
  26. else
  27. print '<div style="font-size: 13; font-weight: bold; color: red">OFFLINE</div>';
  28. ?>

Pozdrawiam
marcio
[zmoderowane] nawet ci sie pokombininowac nie chce?Masz dzial na gotowce
  1. <?php
  2.  mysql_connect(localhost,root,pas);
  3.  if(isset($_GET['id'])) {
  4. $id = intval($_GET['id']);
  5.  
  6.  $sql = mysql_query("SELECT id,ip,port,nazwa,client,loncze,acc,opis FROM ots WHERE id = '$id' ");
  7.  
  8. while($rekord=mysql_fetch_array($sql)) {
  9.  
  10. echo 'Nazwa: ';
  11. echo "<strong>".$rekord['nazwa']."</strong><br>";//wyswietlasz rekordy o podanym ID
  12. echo 'Ip/Host: ';
  13. echo "<strong>".$rekord['ip']."</strong><br>";
  14. echo 'Acc: ';
  15. echo "<strong>".$rekord['acc']."</strong><br>";
  16. echo 'Port: ';
  17. echo "<strong>".$rekord['port']."</strong><br>";
  18. echo 'Klient: ';
  19. echo "<strong>".$rekord['client']."</strong><br>";
  20. echo 'Łoncze: ';
  21. echo "<strong>".$rekord['loncze']."</strong><br><hr />";
  22. echo '<left>Opis Serwera: </left><br>';
  23. echo "<strong>".$rekord['opis']."</strong><br><hr />";
  24.  
  25. if($sock = @fsockopen($rekord['ip'], $rekord['port'], $errno, $errstr, 1)) ? 'Online' : 'Offline';
  26.  
  27. //lub bo nie jestem pewny :)
  28.  
  29. if($sock = @fsockopen($rekord['ip'], $rekord['port'], $errno, $errstr, 1)) $online = 'Online'; else $online = 'Offline';
  30.  
  31.  echo 'Status Serwera: '.$sock.'<br>';
  32.  echo 'Status Serwera: '.$online.'<br>';
  33.  }
  34. }
  35. ?>

Jakos tak to tak na szybko

// Dostajesz ostrzeżenie za wulgaryzmy na forum.
// ~webdicepl


Hehe juz nie bede no ale coz w sumie nie bylo to przeklenstwo
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.