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 fsockopen需要 PHP.ini 中 allow_url_fopen 选项开启。
使用fsockopen获取网页内容
具体源代码如下:
<?php
$host = \"www.manongjc.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.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!\";
?> 继续阅读与本文标签相同的文章
下一篇 :
对照检查!高效程序员几乎都有这七项技能
-
华为轮值董事长郭平:虚拟技术创造现实价值
2026-05-14栏目: 教程
-
微软Windows 10 11月更新准备就绪!
2026-05-14栏目: 教程
-
花3000块发明最牛输入法!打字速度冠绝群雄,现在却被遗忘了
2026-05-14栏目: 教程
-
二进制、八进制、十六进制在现实当中有什么意义?
2026-05-14栏目: 教程
-
无需屏幕、裸眼3D,今后广告等可直接成像在空气中
2026-05-14栏目: 教程
