System Idle Process What processes use PHP Socke to submit data to a specified page

Source: Internet
Author: User
With the load post in jquery and so on, I can't get the result I want! So suddenly-----these days think of things are white, now have to do so
Now I want to submit the data in PHP to the specified page, and there should be a return value.
So I found this function, but didn't try, I think I don't know if the space can get through
It's from the village!

Copy the Code code as follows:


/*-----------------------------------------------------------
* Function: Use PHP Socke to submit data to the specified page
*
* Author: honghe.c
*
* Description: Post ($url, $data)
*
* $url = ' http://www.jb51.net ';
* $data [user] = ' hong ';
* $data [Pass] = ' Xowldo ';
* Echo Post ($url, $data);
*-----------------------------------------------------------*/
Function post ($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);
}
$fp = Fsockopen ($url [' Host '], $url [' Port ']? $url [' Port ']: 80);
if (! $fp) return "Failed to open socket to $url [host]";
Fputs ($FP, sprintf ("POST%s%s%s http/1.0n", $url [' Path '], $url [' query ']? "?": "", $url [' query ']);
Fputs ($FP, "Host: $url [host]n");
Fputs ($fp, "Content-type:application/x-www-form-urlencodedn");
Fputs ($FP, "Content-length:".) Strlen ($encoded). "N");
Fputs ($fp, "Connection:closenn");
Fputs ($fp, "$encodedn");
$line = fgets ($fp, 1024);
if (!eregi ("^HTTP/1. ", $line)) return;
$results = ""; $inheader = 1;
while (!feof ($fp)) {
$line = fgets ($fp, 1024);
if ($inheader && ($line = = "N" | | $line = = "rn") {
$inheader = 0;
}
ElseIf (! $inheader) {
$results. = $line;
}
}
Fclose ($FP);
return $results;
}
/*
$url = ' http://video.xxx.com:80/game_vm.php ';
$data [' gid '] = ' 1 ';
Echo Post ($url, $data);
*/
?>

The above describes what the system Idle process is doing using PHP Socke to submit data to the specified page, including what the system Idle process is, and hopefully help friends who are interested in PHP tutorials.

  • Contact Us

    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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.