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.