This function will post data to the HTTP server, using the user:pass base64(basic)
authentication algorithm.
It can also post browser agent, so web server would think it's a normal user (enter smth
like "Mozilla/4.0 (Macintosh; I; PPC)" in the agent.
Works great for parsing protected content.
To use reply from the server, utilize $reply variable.
example to run the function :
<?
HTTPpost("www.site.com","/cgi-bin/test.pl","data=hello","johny","walker","Mozilla/4.0
(compatible; MSIE 5.5; Windows NT 5.0)");
?>
function HTTPost($host, $path, $data_to_send,$user,$pass,$agent) {
$fp = fsockopen($host,80, &$err_num, &$err_msg, 10);
if (!$fp) {
echo "$err_msg ($err_num)<br>\n";
} else {
$auth = $user.":".$pass ;
$string=base64_encode($auth);
echo $string;
fputs($fp, "POST $path HTTP/1.1\r\n");
fputs($fp, "Authorization: Basic ".$string."\r\n");
fputs($fp, "User-Agent: ".$agent."\n");
fputs($fp, "Host: $host\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
fputs($fp, "Content-length: ".strlen($data_to_send)."\n");
fputs($fp, "Connection: close\n\n");
fputs($fp, $data_to_send);
for ($i = 1; $i < 10; $i++){$reply = fgets($fp, 256);}
fclose($fp);
}}