php源碼 fsockopen獲取網(wǎng)頁內(nèi)容實例詳解
PHP fsockopen函數(shù)說明:
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這個函數(shù)
PHP fsockopen需要 PHP.ini 中 allow_url_fopen 選項開啟。
使用fsockopen獲取網(wǎng)頁內(nèi)容
具體源代碼如下:
<?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獲取網(wǎng)頁內(nèi)容實例詳解的知識,有需要的小伙伴可以參考下,謝謝大家對本站的支持!
相關文章
ubutu 16.04環(huán)境下,PHP與mysql數(shù)據(jù)庫,網(wǎng)頁登錄驗證實例講解
下面小編就為大家?guī)硪黄猽butu 16.04環(huán)境下,PHP與mysql數(shù)據(jù)庫,網(wǎng)頁登錄驗證實例講解。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-07-07
通過修改Laravel Auth使用salt和password進行認證用戶詳解
這篇文章主要給大家介紹了關于通過修改Laravel Auth使用salt和password進行認證用戶的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面來一起看看吧。2017-08-08
使用PHP備份MySQL和網(wǎng)站發(fā)送到郵箱實例代碼
這篇文章主要介紹了使用PHP備份MySQL和網(wǎng)站發(fā)送到郵箱的方法,大家參考使用吧2013-11-11

