Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Wywołanie skryptu
Forum PHP.pl > Forum > PHP
azneme
Witam,
posiadam prosty skrypt php składający się z 3 plików:
stats.php:
  1. <?php ob_start(); include('p.php'); ?>
  2. <p align="right"><font color="white" size="2">Gracze: <?php echo $dust_2['players'].'/'.$dust_2['max']; ?> | Mapa: <?php echo substr($dust_2['map'], 0, 22);?><?php echo substr($dust_2['next_map'], 0, 22);?><?php echo $sdust_2; ?> </font></p>
  3. <?php ob_end_flush(); ?>

p.php:
  1. <?php
  2. require_once('class.hlsocket.php');
  3. $dust_2ip = '193.33.176.205:27015';
  4. $hlsocket = new HLSocket('193.33.176.205', 27015);
  5. $dust_2 = $hlsocket->details();
  6. if($dust_2['map'] == '')
  7. if($dust_2['next_map'] == '')
  8. $hlsocket->close();
  9. ?>

oraz
class.hlsocket.php:
  1. <?php
  2. /**
  3.  * File is released under GPL as can be found on
  4.  * <a href="http://www.gnu.org/licenses/gpl.html" target="_blank">http://www.gnu.org/licenses/gpl.html</a>
  5.  */
  6.  
  7. /* Info string */
  8. define('A2S_INFO', "\xFF\xFF\xFF\xFF\x54\x53\x6F\x75\x72\x63\x65\x20\x45\x6E\x67\x69\x6E\x65\x20\x51\x75\x65\x72\x79\x00");
  9.  
  10. /* Replies for HL Version 1 and Version 2 (aka Source) */
  11. define('REPLY_INFO_HL1', 'm');
  12. define('REPLY_INFO_HL2', 'I');
  13.  
  14. /* Definitions of the bytes */
  15. define('BYTE', 1);
  16. define('BYTE_NUM', BYTE + 1);
  17. define('SHORT', BYTE_NUM + 1);
  18. define('LONG', SHORT + 1);
  19. define('FLOAT', LONG + 1);
  20. define('STRING', FLOAT + 1);
  21.  
  22. /**
  23.  * The socket class
  24.  * @author Herwin Weststrate aka Hdez
  25.  * @contact hdez@counter-strike.nl
  26.  * @version 2005.10.21
  27.  */
  28. class HLSocket
  29. {
  30. /* The socket file descriptor */
  31. var $_socket;
  32.  
  33. /* The way to split the incoming data */
  34. var $_split_info_hl2 = array('type' => BYTE, 'bersion' => BYTE_NUM, 'hostname' => STRING, 'map' => STRING, 'gamedir' => STRING, 'gamedesc' => STRING, 'appid' => SHORT, 'unknown' => BYTE_NUM, 'players' => BYTE_NUM, 'max' => BYTE_NUM, 'bots' => BYTE_NUM, 'dedicated' => BYTE, 'os' => BYTE, 'passworded' => BYTE_NUM, 'secure' => BYTE_NUM, 'gameversion' => STRING);
  35. var $_split_info_hl1 = array('type' => BYTE, 'ip' => STRING, 'hostname' => STRING, 'map' => STRING, 'gamedir' => STRING, 'gamedesc' => STRING, 'players' => BYTE_NUM, 'max' => BYTE_NUM, 'version' => BYTE_NUM, 'dedicated' => BYTE, 'os' => BYTE, 'passworded' => BYTE_NUM, 'secure' => BYTE_NUM, 'gameversion' => STRING);
  36.  
  37. /**
  38. * Create a new socket
  39. * @param $host The ip or hostname
  40. * @param $port The port
  41. */
  42. function HLSocket($host, $port)
  43. {
  44. $this->connect($host, $port);
  45. }
  46. /**
  47. * Actually make the connection to the host
  48. * @param $host The ip or hostname
  49. * @param $port The port
  50. */
  51. function connect($host, $port)
  52. {
  53. $this->_socket = @fsockopen('udp://'.$host, $port);
  54. if (!$this->_socket)
  55. echo 'Error met connecten';
  56. stream_set_timeout($this->_socket, 1); // Set timeout to 1 sec
  57. }
  58.  
  59. /**
  60. * Close the connection (and the socket fd)
  61. */
  62. function close()
  63. {
  64. fclose($this->_socket);
  65. }
  66.  
  67. /**
  68. * Query the server for the details
  69. * @return associative array with the game info
  70. */
  71. function details()
  72. {
  73. $this->write(A2S_INFO);
  74. $data = $this->read();
  75. $res = array();
  76. switch(substr($data, 0, 1))
  77. {
  78. case REPLY_INFO_HL1:
  79. $res = $this->split($this->_split_info_hl1, $data);
  80. break;
  81. case REPLY_INFO_HL2:
  82. $res = $this->split($this->_split_info_hl2, $data);
  83. break;
  84. }
  85. return $res;
  86. }
  87.  
  88. /**
  89. * Write the given message over the socket
  90. * @param $msg The message to be written
  91. * @deprecated This should be issued as a private function
  92. */
  93. function write($msg)
  94. {
  95. fwrite($this->_socket, $msg);
  96. }
  97.  
  98. /**
  99. * Read from the socket
  100. * @return The data from the socket (excluding the first four [useless] bytes)
  101. * @deprecated This should be issued as a private function
  102. */
  103. function read()
  104. {
  105. $data = fread($this->_socket, 1);
  106. $status = socket_get_status($this->_socket);
  107. if (isset($status['unread_bytes']) && $status['unread_bytes'] > 0)
  108. $data .= fread($this->_socket, $status['unread_bytes']);
  109. return substr($data, 4);
  110. }
  111.  
  112. /**
  113. * Split the given datatype from $data String and return the value
  114. * @param $type The data type [BYTE .. STRING]
  115. * @param $data The current data String
  116. * @return The value of the given data type from $data
  117. * @deprecated This should be issued as a private function
  118. */
  119. function splititem($type, &$data) {
  120. $add = '';
  121. switch ($type)
  122. {
  123. case BYTE:
  124. $add = substr($data, 0, 1);
  125. $data = substr($data, 1);
  126. break;
  127. case BYTE_NUM:
  128. $add = ord(substr($data, 0, 1));
  129. $data = substr($data, 1);
  130. break;
  131. case SHORT:
  132. $add = ord(substr($data, 0, 1));
  133. $data = substr($data, 1);
  134. break;
  135. case LONG:
  136. $add = ord(substr($data, 0, 1));
  137. $data = substr($data, 1);
  138. break;
  139. case STRING:
  140. do
  141. {
  142. $char = substr($data, 0, 1);
  143. if ($char != "\x00")
  144. $add .= $char;
  145. $data = substr($data, 1);
  146. }
  147. while ($char != "\x00");
  148. break;
  149. }
  150. return $add;
  151. }
  152.  
  153. /**
  154. * Split the given datatypes from $data String and return the value
  155. * @param $array The data type [BYTE .. STRING] as values of an
  156. * associative array. The keys are also the keys of
  157. * the return array
  158. * @param $data The current data String
  159. * @return Associative array with keys of $array and values read from $data
  160. * @deprecated This should be issued as a private function
  161. */
  162. function split($array, $data)
  163. {
  164. $res = array();
  165. foreach ($array as $k=>$v)
  166. $res[$k] = $this->splititem($v, $data);
  167. return $res;
  168. }
  169. }
  170.  
  171. ?>

pokazuje on tekstowy status graczy na serwerze Half-Life (Ilość graczy / Max graczy | Następna mapa:)
Chciałbym teraz ten status dodać na forum tak, by wyglądało to mniej więcej podobnie do tego:

Próbowałem zrobić to przez <iframe> ale wyszło tak:

prawdopodobnie przez niewidoczne obramowanie forum rozciągnęło się na wysokość.
Czy dałoby rade w jakiś inny sposób bez rozciągnięcia forum uruchomić ten skrypt tak by wyglądał jak na 1 screenie ?
Bardzo proszę o pomoc
muniekw
W pierwszym skrypcie masz
  1. <p align="right">
spróbuj innych znaczników np.
  1. <div style="margin:0px; padding:0px; float: left;"></div>
azneme
Znów w miejscu opisu tragiczna szpara:

Dodam jeszcze że dodaje to poprzez kod:
  1. <iframe scrolling="no" frameborder="0" style="border: none" src="/stat.php">Twoja przeglądarka nie obsługuje ramek!</iframe>

Autor skryptu zaleca
  1. <iframe scrolling="no" frameborder="0" style="width: 100%; height: 280px; border: none" src="TUTAJ DAJESZ LINK DO TEGO STATUSU">Twoja przeglądarka nie obsługuje ramek!</iframe>

ale nawet po zmniejszeniu width i height nie wygląda to tak jak należy :<
Wydaje mi się że problem leży właśnie w tym iframe, może da się to w jakiś inny sposób(html) otworzyć?
help smile.gif
muniekw
Wydaje mi się, że musisz kombinować ze stylami. Zobacz style np w FIREBUGU i pokombinuj. Tak na "sucho" to ciężko coś więcej powiedzieć.
azneme
Niestety, ten sam problem ;f
muniekw
Masz to gdzieś udostępnione, żeby zobaczyć całość?
arfer
Podaj link do samej strony ktora probujesz umiescic w iframe. Jesli ona wyswietla sie normalnie to iframe na forum powinien pokazac ja w oryginalnym ksztalcie.
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.