The phpfsockopen function sends a post request to obtain the webpage content (anti-DDoS collection ). Php Tutorial fsockopen function sends post, get request to get webpage content (anti-DDoS collection) $ post1; $ urlparse_url ($ url); $ hostwww.bkjia.com; $ path; $ query? Actionphp100.co php Tutorial fsockopen function sends post, get request to get webpage content (anti-DDoS collection)
$ 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 'Access successful ';
}
/*
Fsockopen syntax
Resource fsockopen (string $ hostname [, int $ port =-1 [, int & $ errno [, string & $ errstr [, float $ timeout = ini_get ("default_socket_timeout")])
Start a socket to connect to the resources of the specified host.
Php supports goals in the Internet field and descriptions of the socket transport list supported by unix. The supported transfer list can also be retrieved using stream_get_transports ().
The socket is enabled by default in blocking mode. You can switch to non-blocking mode and use stream_set_blocking ().
If the above instance does not understand, let's take a look at it.
*/
$ Fp = fsockopen ("www.bkjia.com", 80, $ 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 );
}
Fsockopen function sends post, get request to get webpage content (anti-DDoS collection) $ post = 1; $ url = parse_url ($ url); $ host = http://www.bkjia.com; $ path = /; $ query =? Action = php100.co...