? Phpsimplepostmethodversion1.0byAndrus (andrus@vnet.ee) Disclaimer: everyonecanchangeorusethiscodehoweverandwherevertheywant;) NB! ForpostingtoMicrosoftplatformwebserversyoumayneedtochangenewlinesnto // Simple post method
// Version 1.0 by Andrus (andrus@vnet.ee)
// Disclaimer:
// Everyone can change or use this code however and wherever they want ;)
// 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 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 ");
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 ));
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.