PHP fsockopen函数说明:
Open Internet or Unix domain socket connection(打开套接字链接)
Initiates a socket connection to the resource specified by target .
fsockopen() returns a file pointer which may be used together with the other file functions (such as fgets(),fgetss(),fwrite(),fclose(),and feof() ).就是返回一个文件句柄
PHP fsockopen需要 PHP.ini 中 allow_url_fopen 选项开启。
使用fsockopen获取网页内容
具体源代码如下:
PHP;">
$request = "GET $page HTTP/1.0\r\n";
$request .= "Host: $host\r\n";
$request .= "Referer: http://www.manongjc.com/page.html\r\n";
$request .= "User-Agent: PHP test client\r\n\r\n";
原文链接:https://www.f2er.com/php/18964.html$request .= "Host: $host\r\n";
$request .= "Referer: http://www.manongjc.com/page.html\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!";
?>