PHP
// Simple Post Method
// Version 1.0 by andrus (andrus@vnet.ee)
// disclaimer:
// Everyone can change or use this code however and wherewant;)
// NB! For posting to microsoft platform Webservers you may need to change newlines "/ n" to "/ r / n"
// Microsoft Always Breaks Standards ...
// send out "browser" Headers
Function Send_Headers ($ fp) {
FPUTS ($ FP, "Accept: * / * / N");
FPUTS ($ FP, "Accept-Language: EN / N");
FPUTS ($ FP, "Connection: Keep-Alive / N");
FPUTS ($ FP, "User-Agent: Mozilla / 4.0 (Compatible; Msie 5.5; Windows 98) / N");
}
// Post Data and Return Replend
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" => $ usrname, "pass" => $ password);
?>