php源码 fsockopen获取网页内容实例详解
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!";
?>
以上就是php源码 fsockopen获取网页内容实例详解的知识,有需要的小伙伴可以参考下,谢谢大家对本站的支持!
相关文章
ubutu 16.04环境下,PHP与mysql数据库,网页登录验证实例讲解
下面小编就为大家带来一篇ubutu 16.04环境下,PHP与mysql数据库,网页登录验证实例讲解。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧2017-07-07
通过修改Laravel Auth使用salt和password进行认证用户详解
这篇文章主要给大家介绍了关于通过修改Laravel Auth使用salt和password进行认证用户的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面来一起看看吧。2017-08-08


最新评论