<address id="ousso"></address>
<form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
  1. php語言

    使用php自動提交表單的方法

    時間:2025-05-19 22:04:36 php語言 我要投稿
    • 相關推薦

    使用php自動提交表單的方法

      介紹了php自動提交表單的方法,結合實例形式分析了php基于fsockopen與curl兩種實現技巧,需要的朋友可以參考下。

      fsockopen和curl都可以做php自動提交表單

      1. fsockopen方法:

      php代碼:

      46

      47

      48

      49

      <?php

      /*-----------------------------------------------------------

      *功能:使用PHP socke 向指定頁面提交數據

      *作者:果凍  說明: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.. 200", $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方法:

      php代碼:

      ?

      1

      2

      3

      4

      5

      6

      7

      8

      9

      10

      11

      12

      13

      14

      <?php

      $url = 'http://localhost/curl/result.php';

      $params = "param=123?m2=333"; //What will 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);

      echo "Results: <br>".$result;

      ?>

      result.php (just for test)

      ?

      1

      2

      3

      <?php

      print_r($_POST);

      ?>

    【使用php自動提交表單的方法】相關文章:

    PHP提交from表單的方法07-05

    php防止表單重復提交的方法10-16

    php提交form表單處理方法07-12

    用PHP提交from表單的處理方法09-06

    如何讓php提交form表單11-06

    php表單提交與$-POST實例分析11-15

    解決表單重復提交問題的PHP代碼11-02

    PHP 表單驗證方法11-01

    php通過記錄IP來防止表單重復提交方法分析10-17

    <address id="ousso"></address>
    <form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
    1. 日日做夜狠狠爱欧美黑人