<?
/*
** Post messages to the host
*/
Function posttohost ($ 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 );
}
$ Port = $ URL [\ 'port \ ']? $ URL [\ 'port \ ']: 80;
$ Fp = fsockopen ($ URL [\ 'host \ '], $ port, $ errno, $ errstr );
If (! $ FP) Return "failed to open socket to $ URL [host] $ port error: $ errno-$ errstr ";
Fputs ($ FP, sprintf ("post % S % s HTTP/1.0 \ n", $ URL [\ 'path \ '], $ URL [\ 'query \ ']? "? ":" ", $ URL [\ 'query \ ']);
Fputs ($ FP, "Host: $ URL [host] \ n ");
Fputs ($ FP, "Content-Type: Application/X-WWW-form-urlencoded \ n ");
Fputs ($ FP, "Content-Length:". strlen ($ encoded). "\ n ");
Fputs ($ FP, "connection: Close \ n ");
Fputs ($ FP, "$ encoded \ n ");
$ 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 = "\ r \ n ")){
$ Inheader = 0;
}
Elseif (! $ Inheader ){
$ Results. = $ line;
}
}
Fclose ($ FP );
return $ results;
}/ * end function posttohost */
?>