HTML beginner |
|
Je kan deze functie gebruiken om de pagina en de inhoud op te vragen.
<?php
function getfromurl( $url ){
$parsed = parse_url( $url );
if( !isset( $parsed['path'] ) ){
$parsed['path'] = "/";
}
$fp = fsockopen( $parsed['host'], 80, $errno, $errstr, 5 );
if( !$fp ){
return $errstr." (".$errno.")<br />";
} else {
$out = "GET ".$parsed['path']." HTTP/1.1\r\n";
$out .= "Host: ".$parsed['host']."\r\n";
$out .= "User-Agent: Googlebot/2.1\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite( $fp, $out );
$contents = "";
$reading = false;
while (!feof($fp)) {
$temp = fgets( $fp, 128 );
if( $reading ){
$contents .= $temp;
}
if( $temp == "\r\n" ){
$reading = true;
}
}
fclose( $fp );
return $contents;
}
}
?>
<?php function getfromurl( $url ){ if( !isset( $parsed['path'] ) ){ $parsed['path'] = "/"; } $fp = fsockopen( $parsed['host'], 80, $errno, $errstr, 5 ); if( !$fp ){ return $errstr." (".$errno.")<br />"; } else { $out = "GET ".$parsed['path']." HTTP/1.1\r\n"; $out .= "Host: ".$parsed['host']."\r\n"; $out .= "User-Agent: Googlebot/2.1\r\n"; $out .= "Connection: Close\r\n\r\n"; $contents = ""; $reading = false; $temp = fgets( $fp, 128 ); if( $reading ){ $contents .= $temp; } if( $temp == "\r\n" ){ $reading = true; } } return $contents; } } ?>
|