PHP fsockopen function sends Post,get request for Web content (anti-anti-capture) _php tutorial

Source: Internet
Author: User
PHP tutorial fsockopen function send Post,get request to get Web content (anti-anti-capture)

$post = 1;
$url = Parse_url ($url);
$host = ' http://www.bkjia.com ';
$path = '/';
$query = '? action=php100.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-agent: $_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-agent: $_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 ';
}
/*
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 the specified host resource.
PHP supports the target in the Internet domain and UNIX in the supported socket transmission list description. The supported transports list can also be retrieved using Stream_get_transports ().

The socket presets will be enabled, blocking mode. You can switch to non-blocking mode using stream_set_blocking ().

If the above example doesn't understand, let's see a Jane.


*/

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

http://www.bkjia.com/PHPjc/445446.html www.bkjia.com true http://www.bkjia.com/PHPjc/445446.html techarticle PHP tutorial fsockopen function send Post,get request to get Web content (anti-anti-collection) $post =1; $url = Parse_url ($url); $host =http://www.bkjia.com; $path =/; $q Uery =?action=php100.co ...

  • 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.