// 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.0/n"); send_headers ($fp); fputs ($fp, "content-type: application/x-www-form-urlencoded/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)."/n/n"); 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));