您的位置:首页 > 编程语言 > PHP开发

详解PHP fsockopen的使用方法(获取页面的头信息)

2011-05-23 14:53 1131 查看
1.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 选项开启。

$fp = fsockopen("www.example.com",
80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />/n";
} else {
$out = "GET / HTTP/1.1/r/n";
$out .= "Host: www.example.com/r/n";
$out .= "Connection: Close/r/n/r/n";

fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: