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