Share php functions for retrieving http Content
This article mainly introduces php functions for obtaining http content. Now, I want to share it with you. If you need it, please take a look.
The Code is as follows:
<? Php
Function http_open ($ url, $ data, $ cookie = null, $ method = "GET", $ timeout = 60 ){
$ Options = array ();
$ Options ['http'] ['method'] = $ method;
$ Options ['http'] ['user _ agent'] = $ _ SERVER ['HTTP _ USER_AGENT '];
$ Options ['http'] ['timeout'] = $ timeout;
If ($ method = "POST "):
$ Length = strlen ($ data );
$ Options ['http'] ['header'] = "Content-type: application/x-www-form-urlencodedrn ".
"Content-Length: {$ length} rn ".
"P3P: CP =" CURa ADMa DEVa PSAo PSDo our bus uni pur int dem sta pre com nav otc noi dsp cor "rn ".
"Cookie: {$ cookie} rn ".
"Connection: closern ";
$ Options ['http'] ['content'] = $ data;
Else:
$ Options ['http'] ['header'] = "Content-type: application/x-www-form-urlencodedrn ".
"P3P: CP =" CURa ADMa DEVa PSAo PSDo our bus uni pur int dem sta pre com nav otc noi dsp cor "rn ".
"Cookie: {$ cookie} rn ".
"Connection: closern ";
Endif;
$ Context = stream_context_create ($ options );
Return file_get_contents ($ url, 0, $ context );
}
Echo http_open ("http: // localhost/1.php"," username = haowei "," id = 5 "," POST ");