curl, fsocketopen, socket three functions to capture html page_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:39:12
Original
1041 people have browsed it

(1) php - curl

<?php    $ch_article = curl_init();    $url        = 'www.baidu.com';    curl_setopt($ch_article, CURLOPT_URL, $url);    curl_setopt($ch_article, CURLOPT_RETURNTRANSFER, 0);    curl_setopt($ch_article, CURLOPT_HEADER, 0);    $article_output = curl_exec($ch_article);    curl_close($ch_article);    echo $article_output;?>
Copy after login


(2) php - fsocketopen

<?php$fp = fsockopen("www.baidu.com", 80, $errno, $errstr, 30);$out = "GET / HTTP/1.1\r\n";$out .= "Host: www.baidu.com\r\n";$out .= "Connection: Close\r\n\r\n";fwrite($fp, $out);while (!feof($fp)) {    echo fgets($fp, 128);}fclose($fp);?>
Copy after login


(3) php - socket

<?php$url='www.baidu.com';$Port = 80;$host_ip  = gethostbyname('www.baidu.com');$Header  .= trim('Host:www.baidu.com')."\r\n";$Header  .= trim('Connection: Close')."\r\n";$method   = 'GET';$Request  = $method." " . '/' . " HTTP/1.1\r\n";$Request .= $Header;$Request .= "\r\n";$sockHttp    = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);$resSockHttp = socket_connect($sockHttp, $host_ip, $Port);socket_write($sockHttp, $Request, strlen($Request));$Response = '';while ($Read_data = socket_read($sockHttp, 4096)){	$Response .= $Read_data;}socket_close($sockHttp);echo $Response;?>
Copy after login


Copyright statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template