Share php functions for retrieving http Content

Source: Internet
Author: User

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 ");

 

 

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.