Phpfsockopen function sends post, get request to get webpage content (anti-DDoS collection) _ PHP Tutorial

Source: Internet
Author: User
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...

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.