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.