« Blog Home

§ Send POST request from PHP

A way to send a POST request from PHP.

The PostToHost function does the work.  The code above it shows examples of how to call it.




function add_to_newsletter($name,$email) {


  PostToHost('localhost', '/mailing/subscribe/enter.php', $post_data);

function PostToHost($host, $path, $data_to_send) {
  $eol = "rn";
  $fp = fsockopen($host,80);
  fputs($fp, "POST $path HTTP/1.1".$eol );
  fputs($fp, "Host: $host".$eol );
  fputs($fp, "Content-type: application/x-www-form-urlencoded".$eol );
  fputs($fp, "Content-length: ".strlen($data_to_send).$eol );
  fputs($fp, "Connection: close".$eol.$eol );
  fputs($fp, $data_to_send);



last edited on January 29th, 2009 at 12:30 PM


No Comments Here. Add yours below!

Add your comment

Email: (Will not be displayed - Privacy policy)
  random image I can't read it!
Give me a different one!
Verify Post: Input the text from the image above to verify this post (helps prevent spam)

« Blog Home

“If everybody minded their own business,” said the Duchess in a hoarse growl, “the world would go round a deal faster than it does.”
Lewis Carroll, quoted in To Say Nothing of the Dog, Connie Willis