Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> fsockopen
kiamil
post 3.09.2008, 12:25:07
Post #1





Grupa: Zarejestrowani
Postów: 26
Pomógł: 0
Dołączył: 16.03.2008

Ostrzeżenie: (0%)
-----


Zwraca mi wiadomość:

HTTP/1.1 200 OK Date: Wed, 03 Sep 2008 11:24:27 GMT Server: Apache/2.2.8 (Win32) DAV/2 mod_ssl/2.2.8 OpenSSL/0.9.8g mod_autoindex_color PHP/5.2.5 X-Powered-By: PHP/5.2.5 Content-Length: 13 Keep-Alive: timeout=5, max=100 Connection: Keep-Alive Content-Type: text/html To jest test!

A chciałbym żeby mi wyświetlało samo "To jest tekst!" - jak to zrobić?
Go to the top of the page
+Quote Post
bim2
post 3.09.2008, 14:09:33
Post #2





Grupa: Zarejestrowani
Postów: 1 873
Pomógł: 152
Dołączył: 9.04.2006
Skąd: Berlin

Ostrzeżenie: (0%)
-----


  1. <?php
  2. $zm = explode("\n\n", $fsockopen);
  3. unset($zm[0]);
  4. echo implode("\n\n", $zm);
  5. ?>


--------------------
Go to the top of the page
+Quote Post
kiamil
post 3.09.2008, 14:17:29
Post #3





Grupa: Zarejestrowani
Postów: 26
Pomógł: 0
Dołączył: 16.03.2008

Ostrzeżenie: (0%)
-----


Nadal się wyświetla, oto kod z zamontowanym skryptem:
  1. <?php
  2.  
  3. $host = '127.0.0.1';
  4. $uri = '/fsockopen1.php';
  5.  
  6. $nl = "r\n";
  7. $header = 'GET ' . $uri . ' HTTP/1.1' . $nl;
  8. $header .= 'Host: '. $host . $nl;
  9. $header .= 'User-Agent: ' . phpversion() . $nl;
  10. $header .= 'Accept-Language: pl,en-us;q=0.7,en;q=0.3' . $nl;
  11. $header .= 'Accept-Charset: ISO-8859-2,utf-8;q=0.7,*;q=0.7' . $nl;
  12. $header .= 'Keep-Alive: 300' . $nl;
  13. $header .= 'Connection: keep-alive' . $nl . $nl;
  14.  
  15. $sock = fsockopen($host, 80, $errno, $errstr) or
  16. die($errno . ' - ' . $errstr);
  17. $zm = explode("\n\n", $sock);
  18. unset($zm[0]);
  19. echo implode("\n\n", $zm);
  20.  
  21. fwrite($sock, $header);
  22.  
  23. while(!feof($sock)) echo fgets($sock, 1024);
  24.  
  25. fclose($sock); 
  26.  
  27. ?>
Go to the top of the page
+Quote Post
ddiceman
post 3.09.2008, 14:46:22
Post #4





Grupa: Zarejestrowani
Postów: 326
Pomógł: 121
Dołączył: 23.07.2008
Skąd: Wrocław

Ostrzeżenie: (0%)
-----


A nie latwiej Ci bedzie uzyc cURL'a albo file_get_contents()? Problem lezy w tym, ze przez socket otrzymujesz pelna odpowiedz serwera wraz z naglowkami HTTP.

Mozesz ich sie tez pozbyc mniej-wiecej tak:
  1. <?php
  2. $naglowek = get_headers($uri);
  3. $sock = str_replace( implode('\n', $naglowek), '', $sock);
  4. ?>

aczkolwiek to tak z palca jest pisane i bez dopracowania: musialbys sie przyjrzec zmiennej $naglowek
Go to the top of the page
+Quote Post
bim2
post 3.09.2008, 16:24:46
Post #5





Grupa: Zarejestrowani
Postów: 1 873
Pomógł: 152
Dołączył: 9.04.2006
Skąd: Berlin

Ostrzeżenie: (0%)
-----


  1. <?php
  2. $sock = fsockopen($host, 80, $errno, $errstr) or
  3. die($errno . ' - ' . $errstr);
  4.  
  5. fwrite($sock, $header);
  6. $zm = '';
  7. while(!feof($sock)) $zm .= fgets($sock, 1024);
  8. $zm = explode("\n\n", $zm);
  9. unset($zm[0]);
  10. echo implode("\n\n", $zm);
  11.  
  12. fclose($sock);
  13. ?>


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 12.06.2025 - 14:24