Function example for php to obtain http content
-
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: // bbs.it-home.org
- $ 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 ");
|