PHP fsockopen函數說明:
Open Internet or Unix domain socket connection(開啟套接字連結)
Initiates a socket connection to the resource specified by target .
, openov the other file functions (such as fgets() , fgetss() , fwrite() , fclose() , and feof() ).就是回傳一個檔案句柄
開啟PHP fsockopenopen這個函數
PHP fsockopenP. 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網頁內容!
更多php原始碼 fsockopen取得網頁內容實例詳解相關文章請關注PHP中文網!