How PHP automatically submits the form (based on fsockopen and curl), Fsockopencurl
This example describes how PHP automatically submits forms based on the Fsockopen and Curl implementations. Share to everyone for your reference, as follows:
Fsockopen and curl can do PHP auto-submit Form
1. Fsockopen Method:
PHP Code:
<?php/*-----------------------------------------------------------* Function: Use PHP Socke to submit data to a specific page * Author: Jelly Description: Post ($url , $data) * * $url = ' http://www.xxx.com:8080/login.php '; * $data [user] = ' hong '; * $data [pass] = ' Xowldo '; * echo Post ($url, $data); *-----------------------------------------------------------*/function post ($url, $data) {$url = Parse_url ($url); if (! $url) return "couldn ' t parse url"; if (!isset ($url [' Port ']) {$url [' port '] = "";} if (!isset ($url [' query '])) {$url [' query '] = "";} $encoded = ""; while (list ($k, $v) = each ($data)) {$encoded. = ($encoded? "&": ""); $encoded. = Rawurlencode ($k). " = ". Rawurlencode ($v); } $fp = Fsockopen ($url [' Host '], $url [' Port ']? $url [' Port ']: 80); if (! $fp) return "Failed to open socket to $url [host]"; Fputs ($FP, sprintf ("POST%s%s%s http/1.0n", $url [' Path '], $url [' query ']? "?": "", $url [' query ']); Fputs ($FP, "Host: $url [host]n"); Fputs ($fp, "Content-type:application/x-www-form-urlencodedn"); FpuTS ($fp, "Content-length:". Strlen ($encoded). "N"); Fputs ($fp, "Connection:closenn"); Fputs ($fp, "$encodedn"); $line = fgets ($fp, 1024); if (!eregi ("^HTTP/1. ", $line)) return; $results = ""; $inheader = 1; while (!feof ($fp)) {$line = Fgets ($fp, 1024); if ($inheader && ($line = = "N" | | $line = = "rn") {$inheader = 0; } elseif (! $inheader) {$results. = $line; }} fclose ($FP); return $results;} /* $url = ' http://video.xxx.com:80/game_vm.php '; $data [' gid '] = ' 1 '; Echo post ($url, $data);*/?>
2. Curl Method:
PHP Code:
<?php $url = ' http://localhost/curl/result.php '; $params = "param=123¶m2=333"; What'll be posted $user _agent = "mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0) "; $ch = Curl_init (); curl_setopt ($ch, curlopt_post,1); curl_setopt ($ch, Curlopt_postfields, $params); curl_setopt ($ch, Curlopt_url, $url); curl_setopt ($ch, curlopt_useragent, $user _agent); curl_setopt ($ch, curlopt_returntransfer,1); $result =curl_exec ($ch); Execut curl_close ($ch);
". $result;? >
result.php (just for test)
<?phpprint_r ($_post);? >
More about PHP related content readers can view the topic: "PHP Socket Usage Summary", "Php Curl Usage Summary", "PHP array" operation Skills Daquan, "PHP Data structure and algorithm tutorial", "PHP Math Skills Summary", " PHP Date and Time usage summary, PHP Object-oriented Programming primer, PHP string usage Summary, PHP+MYSQL Database Operations Primer, and PHP Common database operations Tips Summary
I hope this article is helpful to you in PHP programming.
http://www.bkjia.com/PHPjc/1126069.html www.bkjia.com true http://www.bkjia.com/PHPjc/1126069.html techarticle how PHP automatically submits the form (based on fsockopen and curl), Fsockopencurl This example describes how PHP automatically submits a form based on fsockopen and curl. Share to everyone for your reference ...