Posted By

Wiederkehr on 12/28/08


Tagged

http php textmate post request


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

luman
ginoplusio
jeremyhcobb


PHP POST Request


 / Published in: PHP
 

  1. <?php
  2. function PostToHost($host, $path, $referer, $data_to_send) {
  3. $fp = fsockopen($host, 80);
  4. printf("Open!n");
  5. fputs($fp, "POST $path HTTP/1.1rn");
  6. fputs($fp, "Host: $hostrn");
  7. fputs($fp, "Referer: $refererrn");
  8. fputs($fp, "Content-type: application/x-www-form-urlencodedrn");
  9. fputs($fp, "Content-length: ". strlen($data_to_send) ."rn");
  10. fputs($fp, "Connection: closernrn");
  11. fputs($fp, $data_to_send);
  12. printf("Sent!n");
  13. while(!feof($fp)) {
  14. $res .= fgets($fp, 128);
  15. }
  16. printf("Done!n");
  17. fclose($fp);
  18. return $res;
  19. }
  20.  
  21. $data = "data";
  22.  
  23. printf("Go!n");
  24. $x = PostToHost(
  25. "host",
  26. "path",
  27. "referer",
  28. $data
  29. );
  30. ?>

Report this snippet  

You need to login to post a comment.