PHP fsockopen function Send Post,get request to get Web content (anti-anti collection)

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags anti- content function get host http php php tutorial

PHP tutorial fsockopen function send post,get request get web content (anti-collect)

$post = 1;
$url = Parse_url ($url);
$host = ' http://www.jzread.com ';
$path = '/';
$query = '? action=jzread.com ';
$port = 80;
 
if ($post) {
  $out = post $path http/1.0rn;
  $out. = "Accept: */*rn";
 //$out. = "Referer: $boardurlrn";
  $out. = "Accept-language:zh-cnrn";
  $out. = "CONTENT-TYPE:APPLICATION/X-WWW-FORM-URLENCODEDRN";
  $out. = "User: $_server[http_user_agent]rn";
  $out. = "Host: $hostrn";
  $out. = ' content-length: '. strlen ($post). " RN ";
  $out. = "Connection:closern";
  $out. = "Cache-control:no-cachern";
  $out. = "Cookie: $cookiernrn";
  $out. = $post;
 } else {
  $out = "Get $path http/1.0rn";
  $out. = "Accept: */*rn";
 //$out. = "Referer: $BOARDURLRN ";
  $out. = "Accept-language:zh-cnrn";
  $out. = "User: $_server[http_user_agent]rn";
  $out. = "HosT: $hostrn ";
  $out. = "Connection:closern";
  $out. = "Cookie: $cookiernrn";
 }
  $fp = @fsockopen ($ip $ip: $host), $port, $errno, $errstr, $timeout);
 if (! $fp)
 {
  return ";//note $errstr: $errno rn
 } else {
  return ' successful access ';
&NBSP}
 /*
 fsockopen syntax
 
 resource fsockopen (String $hostname [, int $port =-1 [, int & $errno [, String & $errstr [, Float $timeout = Ini_get ("Default_socket_timeout")]]]
 
  Initiates a socket connection to a resource of the specified host.
    PHP supports goals in the Internet domain and description of UNIX in the supported Sockets transfer list. The supported transport lists can also be retrieved using Stream_get_transports ().
&NBSP
  The socket preset is enabled, blocking mode. You can switch to non-blocking mode using stream_set_blocking ().
&NBSP
  If the above example doesn't make sense, look at Jane.


*/

$fp = Fsockopen ("www.jzread.com", $errno, $errstr, 30);
if (! $fp) {
echo "$errstr ($errno) <br/>n";
else {
$out = "Get/http/1.1rn";
$out. = "HOST:WWW.JZREAD.COMRN";
$out. = "Connection:closernrn";
Fwrite ($fp, $out);
while (!feof ($fp)) {
Echo fgets ($FP, 128);
}
Fclose ($FP);
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.