php专区

 首页 > php专区 > PHP基础 > 函数 > simplepostmethod

simplepostmethod

分享到:
【字体:
导读:
         摘要://simplepostmethod//version1.0byAndrus(andrus@vnet.ee)//Disclaimer://everyonecanchangeorusethiscodehoweverandwherevertheywant;)//NB!ForpostingtoMicrosoftplatfor...

simplepostmethod
// simple post method
// version 1.0 by Andrus (andrus@vnet.ee)

// Disclaimer:
// everyone can change or use this code however and wherever they want ;)

// NB! For posting to Microsoft platform webservers you may need to change newlines "n" to "rn"
// Microsoft always breaks standards ...

    // send out "browser" headers
    function send_headers ($fp) {
        fputs ($fp, "Accept: */*n");
        fputs ($fp, "Accept-Language: enn");
        fputs ($fp, "Connection: Keep-Aliven");
        fputs ($fp, "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)n");
    }

    // post data and return reply
    function post_data ($host, $url, $data) {
        $fp = @fsockopen ($host, 80, $errno, $errstr, 120);
        $ret = "";
                if (strncasecmp ($url, "http://", 7) == 0) $url = substr ($url, 7);
        $p = strpos ($url, '/');
        if (empty ($p)) {
            $req = "/";
        } else {
            $req = substr ($url, $p);
        }
        if ($fp) {
            fputs ($fp, "POST $req HTTP/1.0n");
            send_headers ($fp);
            fputs ($fp, "Content-type: application/x-www-form-urlencodedn");
            $out = "";
            while (list ($k, $v) = each ($data)) {
                if(strlen($out) != 0) $out .= "&";
                $out .= rawurlencode($k). "=" .rawurlencode($v);
            }
            $out = trim ($out);
            fputs ($fp, "Content-length: ".strlen($out)."nn");
            fputs ($fp, "$out");
            fputs ($fp, "n");
            while(!feof($fp)){
                $ret .= fgets($fp,128);
            }
        fclose ($fp);
        }
        return $ret;
    }
// example how to use:

// following code will post variables "login" and "pass" to server "www.something.com" script "/submit.php"
$reply = post_data ("www.something.com", "/submit.php", array ("login" => $username, "pass" => $password));
simplepostmethod
分享到:
给文字加上拼音
给文字加上拼音   应用例,给文字加上拼音 给文字加上拼音
示例
示例                           显示 [ - ] 条记录,共条记录                                                                                           ...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……