<html>
<head>
<title>Retrieving a Web page using fsockopen()</title>
</head>
<body>
<?php
$host = "www.java2java.com";
$page = "/index.htm";
$fp = fsockopen( "$host", 80, &$errno, &$errdesc);
if ( ! $fp )
die ( "Couldn't connect to $host:\nError: $errno\nDesc: $errdesc\n" );
$request = "GET $page HTTP/1.0\r\n";
$request .= "Host: $host\r\n";
$request .= "Referer: http://www.java2java.com/index.htm\r\n";
$request .= "User-Agent: PHP test client\r\n\r\n";
$page = array();
fputs ( $fp, $request );
while ( ! feof( $fp ) )
$page[] = fgets( $fp, 1024 );
fclose( $fp );print "the server returned ".(count($page))." lines!";
?>
</body>
</html>
|