Autor Zpráva
Kubisek
Profil *
mam este jeden dotaz.. otvaram vzdialene HTML subory pomocou fsockopen().. a vsetko funguje napriklad na domene vo formate www.yahoo.com. ked uz chcem otvorit napriklad http://www.yahoo.com/r/m7 tak mi pise PHP chybu

Warning: fsockopen(): php_network_getaddresses: gethostbyname failed in file.php on line 141

a v dokumentacii som nasiel, teda v dodatku, toto:

http://sk2.php.net/manual/sk/transports.php

podla vsetkeho do parametru toho fsockopen nemozem zadat stranky s lomitkom(laicky)?.. ale aky to ma potom vyznam? ja praveze potrebujem otvarat aj tie hore uvedene, nie len hlavnu stranku.. nie je na to nejake ine riesenie ako otvarat ostatne?

dakujem za kazdu radu...
souki
Profil
Ukaž zdroják...
Kubisek
Profil *
no mal som toto(stiahnute z php.net/fsockopen):

<?php

function decode_header ( $str )
{
$part = preg_split ( "/ ? /", $str, -1, PREG_SPLIT_NO_EMPTY );

$out = array ();

for ( $h = 0; $h < sizeof ( $part ); $h++ )
{
if ( $h != 0 )
{
$pos = strpos ( $part[$h], ':' );

$k = strtolower ( str_replace ( ' ', '', substr ( $part[$h], 0, $pos ) ) );

$v = trim ( substr ( $part[$h], ( $pos + 1 ) ) );
}
else
{
$k = 'status';

$v = explode ( ' ', $part[$h] );

$v = $v[1];
}

if ( $k == 'set-cookie' )
{
$out['cookies'][] = $v;
}
else if ( $k == 'content-type' )
{
if ( ( $cs = strpos ( $v, ';' ) ) !== false )
{
$out[$k] = substr ( $v, 0, $cs );
}
else
{
$out[$k] = $v;
}
}
else
{
$out[$k] = $v;
}
}

return $out;
}

function decode_body ( $info, $str, $eol = " " )
{
$tmp = $str;

$add = strlen ( $eol );

$str = '';

if ( isset ( $info['transfer-encoding'] ) && $info['transfer-encoding'] == 'chunked' )
{
do
{
$tmp = ltrim ( $tmp );

$pos = strpos ( $tmp, $eol );

$len = hexdec ( substr ( $tmp, 0, $pos ) );

if ( isset ( $info['content-encoding'] ) )
{
$str .= gzinflate ( substr ( $tmp, ( $pos + $add + 10 ), $len ) );
}
else
{
$str .= substr ( $tmp, ( $pos + $add ), $len );
}

$tmp = substr ( $tmp, ( $len + $pos + $add ) );

$check = trim ( $tmp );

} while ( ! empty ( $check ) );
}
else if ( isset ( $info['content-encoding'] ) )
{
$str = gzinflate ( substr ( $tmp, 10 ) );
}

return $str;
}

if ( ( $io = fsockopen( "www.yahoo.com", 80, $errno, $errstr, 5 ) ) !== false )
{
$send = "GET / HTTP/1.1 ";
$send .= "Host: www.yahoo.com ";
$send .= "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021204 ";
$send .= "Referer: http://www.yahoo.com/ ";
$send .= "Accept: text/xml,application/xml,application/xhtml+xml,";
$send .= "text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,";
$send .= "image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1 ";
$send .= "Accept-Language: en-us, en;q=0.50 ";
$send .= "Accept-Encoding: gzip, deflate, compress;q=0.9 ";
$send .= "Connection: Close ";

fputs ( $io, $send );

$send = '';

do
{
$send .= fgets ( $io, 4096 );

} while ( strpos ( $send, " " ) === false );

$info = decode_header ( $send );

$send = '';

while ( ! feof ( $io ) )
{
$send .= fread ( $io, 8192 );
}

fclose ( $io );

$send = decode_body ( $info, $send );

echo '<h3>Header Array</h3>';
echo '<pre>';
print_r ( $info );
echo '</pre>';
echo '<h3>Document Body</h3>';
echo $send;

}

?>

a nahradil som to jednym riadkom kodu kde je file_get_contents a slape vsetko ok :-D
Acci
Profil
a nahradil som to jednym riadkom kodu kde je file_get_contents a slape vsetko ok :-D
Tak proč používáš funkce určené k něčemu trochu jinému?

Jinak, pokud by jsi chtěl použít tu funkci fsockopen, tak musíš znát trochu HTTP komunikaci, tedy řádek
$send = "GET / HTTP/1.1 "; 

nahradit
$send = "GET /r/m7 HTTP/1.1 "; 
Toto téma je uzamčeno. Odpověď nelze zaslat.

0