How PHP automatically submits forms (based on Fsockopen and curl), fsockopencurl_php tutorial

Source: Internet
Author: User

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&param2=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 ...

  • Large-Scale Price Reduction
    • 59% Max. and 23% Avg.
    • Price Reduction for Core Products
    • Price Reduction in Multiple Regions
    undefined. /
    Connect with us on Discord
    • Secure, anonymous group chat without disturbance
    • Stay updated on campaigns, new products, and more
    • Support for all your questions
    undefined. /
    Free Tier
    • Start free from ECS to Big Data
    • Get Started in 3 Simple Steps
    • Try ECS t5 1C1G
    undefined. /

    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.