Hallo,
function getHTTP($proto,$host,$port,$pfad){
# sendet einen HTTP-Request
$flag=true;
$conn=@[link:http://de3.php.net/manual/de/function.stream-socket-client.php@title=stream_socket_client]((([link:http://de3.php.net/manual/de/function.substr.php@title=substr]($proto,-1)=='p') ? 'tcp://' : 'ssl://').$host.':'.$port,$er,$es,10);
if([link:http://de3.php.net/manual/de/function.is-resource.php@title=is_resource]($conn)){
if($host==$this->host)
[link:http://de3.php.net/manual/de/function.fwrite.php@title=fwrite]($conn,'GET '.$pfad." HTTP/1.1\r\n");
else{
[link:http://de3.php.net/manual/de/function.fwrite.php@title=fwrite]($conn,'HEAD '.$pfad." HTTP/1.1\r\n");
$flag=false;
}
[link:http://de3.php.net/manual/de/function.fwrite.php@title=fwrite]($conn,'Host: '.$host."\r\n");
[link:http://de3.php.net/manual/de/function.fwrite.php@title=fwrite]($conn,"Accept: */*;q=0.9\r\n");
[link:http://de3.php.net/manual/de/function.fwrite.php@title=fwrite]($conn,"Accept-Encoding: gzip,deflate;q=0.9\r\n");
[link:http://de3.php.net/manual/de/function.fwrite.php@title=fwrite]($conn,"Keep-Alive: 60\r\n");
[link:http://de3.php.net/manual/de/function.fwrite.php@title=fwrite]($conn,"Connection: keep-alive\r\n\r\n");
$size=0;
$cont=false;
$tran=false;
if([link:http://de3.php.net/manual/de/function.substr.php@title=substr]([link:http://de3.php.net/manual/de/function.fgets.php@title=fgets]($conn),9,3)==200){
do{ $t=[link:http://de3.php.net/manual/de/function.fgets.php@title=fgets]($conn,21000);
$t=[link:http://de3.php.net/manual/de/function.explode.php@title=explode](":",$t,2);
if([link:http://de3.php.net/manual/de/function.stristr.php@title=stristr]($t[0],'content-encoding')!==false) $cont=[link:http://de3.php.net/manual/de/function.trim.php@title=trim]($t[1]);
elseif([link:http://de3.php.net/manual/de/function.stristr.php@title=stristr]($t[0],'content-length')!==false) $size=[link:http://de3.php.net/manual/de/function.trim.php@title=trim]($t[1]);
elseif([link:http://de3.php.net/manual/de/function.stristr.php@title=stristr]($t[0],'transfer-encoding')!==false) $tran=[link:http://de3.php.net/manual/de/function.trim.php@title=trim]($t[1]);
}while($t[0]!="\r\n");
if($flag){
$t='';
if($tran=='chunked')
while(($c=[link:http://de3.php.net/manual/de/function.hexdec.php@title=hexdec]([link:http://de3.php.net/manual/de/function.trim.php@title=trim]([link:http://de3.php.net/manual/de/function.fgets.php@title=fgets]($conn))))!=0){
$x='';
while([link:http://de3.php.net/manual/de/function.strlen.php@title=strlen]($x.=[link:http://de3.php.net/manual/de/function.fread.php@title=fread]($conn,$c-[link:http://de3.php.net/manual/de/function.strlen.php@title=strlen]($x)))<$c);
$t.=$x;
[link:http://de3.php.net/manual/de/function.fgets.php@title=fgets]($conn);
}
elseif($size<1048577)
if($size>0)
while([link:http://de3.php.net/manual/de/function.strlen.php@title=strlen]($t.=[link:http://de3.php.net/manual/de/function.fread.php@title=fread]($conn,$size-[link:http://de3.php.net/manual/de/function.strlen.php@title=strlen]($t)))<$size);
else
while(![link:http://de3.php.net/manual/de/function.feof.php@title=feof]($conn)){
$t.=($c=[link:http://de3.php.net/manual/de/function.fread.php@title=fread]($conn,4096));
if([link:http://de3.php.net/manual/de/function.strlen.php@title=strlen]($t)>1048575){
$this->error='Resource über 1 MB groß';
break;
}
}
else return('Resource über 1 MB groß');
if($cont && $t!='')
if([link:http://de3.php.net/manual/de/function.stristr.php@title=stristr]($cont,'deflate')!==false) $t=[link:http://de3.php.net/manual/de/function.gzuncompress.php@title=gzuncompress]($t);
elseif([link:http://de3.php.net/manual/de/function.stristr.php@title=stristr]($cont,'gzip')!==false) $t=[link:http://de3.php.net/manual/de/function.gzinflate.php@title=gzinflate]([link:http://de3.php.net/manual/de/function.substr.php@title=substr]($t,10));
}
return($t);
}
else return('Resource nicht da');
}
else return('keine Verbindung');
}
Gruß aus Berlin!
eddi