补充资料
<?
function send_headers ($fp) {
fputs ($fp, "Accept: */*\r\n");
//fputs ($fp, "Accept-Language: en\r\n");
fputs ($fp, "Connection: Keep-Alive\r\n");
fputs ($fp, "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)\r\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 ($p==="") {
$req = "/";
} else {
$req = substr ($url, $p);
}
if ($fp) {
fputs ($fp, "POST $req HTTP/1.0\r\n");
send_headers ($fp);
fputs ($fp, "Content-type: application/x-www-form-urlencoded\r\n");
$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)."\r\n\r\n");
fputs ($fp, "$out");
fputs ($fp, "\r\n");
while(!feof($fp)){
$ret .= fgets($fp);
}
fclose ($fp);
}
return $ret;
}
// example how to use:
// following code will post variables "login" and "pass" to server ("
www.xxxxxxxx.com", script "/submit.php"
$reply = post_data ("
www.xxxxxx.com", "/index.php", array ("Options" => "6"));
echo $reply;
?>
HTTP/1.1 200 OK Date: Tue, 31 Jul 2007 12:09:19 GMT
Server: Apache/2.0.2 (WIN) PHP/5.0.2 mod_fastcgi/mod_fastcgi-SNAP-0304124202
X-Powered-By: PHP/5.0.2
Content-Length: 6256
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive Content-Type: text/html
具体每句话的意思,让人看懂就行,还有返回值的意思,是不是通用于服务器端.