Implement php function sharing to obtain http content. Copy the code as follows :? Phpfunctionhttp_open ($ url, $ data, $ cookienull, $ methodGET, $ timeout60) {$ optionsarray (); $ options [http] [method] $ method; $ options
The code is as follows:
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-urlencoded \ r \ n ".
"Content-Length: {$ length} \ r \ n ".
"P3P: CP = \" CURa ADMa DEVa PSAo PSDo our bus uni pur int dem sta pre com nav otc noi dsp cor \ "\ r \ n ".
"Cookie: {$ cookie} \ r \ n ".
"Connection: close \ r \ n ";
$ Options ['http'] ['content'] = $ data;
Else:
$ Options ['http'] ['header'] = "Content-type: application/x-www-form-urlencoded \ r \ n ".
"P3P: CP = \" CURa ADMa DEVa PSAo PSDo our bus uni pur int dem sta pre com nav otc noi dsp cor \ "\ r \ n ".
"Cookie: {$ cookie} \ r \ n ".
"Connection: close \ r \ n ";
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 ");
The http://www.bkjia.com/PHPjc/825244.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/825244.htmlTechArticle code is as follows :? Php function http_open ($ url, $ data, $ cookie = null, $ method = "GET", $ timeout = 60) {$ options = array (); $ options ['http'] ['method'] = $ method; $ options...