Using PHPfsockopen to simulate POST/GET to transfer data _ php instance

Source: Internet
Author: User
Php can simulate post and get to transfer data to another webpage or site. How can we transmit data? The following is a small Editor to introduce how to use PHPfsockopen to simulate POSTGET to transfer data. You need to take a look at it and use php to simulate post and get to transfer data to other web pages or sites.

$ Arr = array ('user' => 'test', 'Password' => ''); sock_get ($ post_url, $ arr); sock_post ($ post_url, $ arr); // fsocket simulates get to submit function sock_get ($ url, $ query = array () {$ query_str = http_build_query ($ query ); $ info = parse_url ($ url); $ port = isset ($ info ['Port'])? $ Info ['Port']:; $ query_str = empty ($ info ["query"])? $ Query_str: $ info ["query"]. '&'. $ query_str; $ fp = fsockopen ($ info ["host"], $ port, $ errno, $ errstr,); if (! $ Fp) {return FALSE;} // $ head = "GET". $ info ['path']. "? ". $ Info [" query "]." HTTP/. \ r \ n "; $ head =" GET ". $ info ['path']."? ". $ Query_str. "HTTP /. \ r \ n "; $ head. = "Host :". $ info ['host']. "\ r \ n"; $ head. = "\ r \ n"; $ write = fputs ($ fp, $ head); while (! Feof ($ fp) {$ line = fread ($ fp,); echo $ line;} fclose ($ fp); return true ;} // fsockopen simulate POSTfunction sock_post ($ url, $ data = array () {$ query = http_build_query ($ data); $ info = parse_url ($ url ); $ fp = fsockopen ($ info ["host"], $ errno, $ errstr,); $ head = "POST ". $ info ['path']. "? ". $ Info ["query"]. "HTTP /. \ r \ n "; $ head. = "Host :". $ info ['host']. "\ r \ n"; $ head. = "Referer: http ://". $ info ['host']. $ info ['path']. "\ r \ n"; $ head. = "Content-type: application/x-www-form-urlencoded \ r \ n"; $ head. = "Content-Length :". strlen (trim ($ query )). "\ r \ n"; $ head. = "\ r \ n"; $ head. = trim ($ query); $ write = fputs ($ fp, $ head); while (! Feof ($ fp) {$ line = fread ($ fp,); echo $ line ;}}

The above content is for you to share with us how to use PHP fsockopen to simulate POST/GET to transfer data. I hope you will like it. For more information about php fsockopen, please stay tuned to this site. Thank you.

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.