Use PHPsocke to submit data to the specified page. Using loadpost in jquery and so on cannot get the desired result! So suddenly, I thought about all the things I thought about in the past few days. now I have to do this. now I want to submit data to the specified page in php and use load post in jquery, unable to get the desired result! So suddenly ----- I thought about things in the past few days, so now I have.
If you want to submit data to the specified page in php, there should be and return values.
So I found this function, but I didn't try it. I don't know if the space can be used.
It's from the village!
The code is as follows:
/*-----------------------------------------------------------
* Function: use PHP socke to submit data to a specified page.
*
* Author: Honghe. c
*
* Description: post ($ url, $ data)
*
* $ Url = 'http: // www.jb51.net ';
* $ Data [user] = 'Hong ';
* $ Data [pass] = 'xowld ';
* 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 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 .. 200", $ 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 );
*/
?>
Success! So suddenly ----- I thought about things in the past few days. now I have to do this. now I want to submit data to the specified page in php...