Показать сообщение отдельно

  #648  
Старый 20.10.2007, 09:58
spamoney
Участник форума
Регистрация: 26.12.2006
Сообщений: 107
Провел на форуме:
228267

Репутация: 27
По умолчанию

Цитата:
Сообщение от NOmeR1  
spamoney
Поэтому здесь вряд ли получится сделать без сокетов.
Всем спасибо, что сказали про сокеты, а то я в php как то не очень по этому сам бы не догнал, сделал через сокеты, вроде получилось, правда там наверное много лишннего кода, т.к фук-цию function httpSocketConnection нашел в полезных скриптах:

PHP код:
<?php

function httpSocketConnection($host$method$path$data
   { 
       
$method strtoupper($method);        
       
       if (
$method == "GET"
       { 
           
$path.= '?'.$data
       }    
       
       
$filePointer = @fsockopen($host80$errorNumber$errorString); 
       
       if (!
$filePointer
       { 
           exit(
'Failed opening http socket connection: '.$errorString.' ('.$errorNumber.')<br/>\n'); 
           return 
false
       } 

       
$requestHeader $method." ".$path."  HTTP/1.1\r\n"
       
$requestHeader.= "Host: ".$host."\r\n"
       
$requestHeader.= "User-Agent:      Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0\r\n"
       
$requestHeader.= "Content-Type: application/x-www-form-urlencoded\r\n"

       if (
$method == "POST"
       { 
           
$requestHeader.= "Content-Length: ".strlen($data)."\r\n"
       } 
       
       
$requestHeader.= "Connection: close\r\n\r\n"
       
       if (
$method == "POST"
       { 
           
$requestHeader.= $data
       }            

       
fwrite($filePointer$requestHeader); 
       
       
$responseHeader ''
       
$responseContent ''

       do 
       { 
           
$responseHeader.= fread($filePointer1); 
       } 
       while (!
preg_match('/\\r\\n\\r\\n$/'$responseHeader)); 
       
       
       if (!
strstr($responseHeader"Transfer-Encoding: chunked")) 
       { 
           while (!
feof($filePointer)) 
           { 
               
$responseContent.= fgets($filePointer128); 
           } 
       } 
       else 
       { 

           while (
$chunk_length hexdec(fgets($filePointer))) 
           { 
               
$responseContentChunk ''
           
               
//logEventToTextFile('debug', $chunk_length); 
               
$read_length 0
               
               while (
$read_length $chunk_length
               { 
                   
$responseContentChunk .= fread($filePointer$chunk_length $read_length); 
                   
$read_length strlen($responseContentChunk); 
               } 

               
$responseContent.= $responseContentChunk
               
               
fgets($filePointer); 
               
           } 
           
       } 

       
//logEventToTextFile('debug', $responseContent); 
       
       
       
return chop($responseContent); 
   } 

$bb=0;
 for(
$f=0;$f<3;$f++){  


$data=""
$host "anekdotov.net"
$path "http://anekdotov.net/vovochka/index-page-$f.html"
$method "GET"


$a=httpSocketConnection($host$method$path$data);

 
$file preg_match_all("#<input type=hidden name=story value='(.*?)<INPUT type=image src=#si",$a,$frazes);  


 for(
$i=0;$i<$file;$i++){  
     echo 
"<hr>".$frazes[1][$i]."\r\n<hr>";  
  }  
$bb++;
}
$vsego=$bb*$file;
echo 
"Анекдотов на странице: <font color=red>$file</font><br>";
echo 
"Всего Анекдотов: <font color=green>$vsego</font>";

?>
 
Ответить с цитированием